【问题标题】:execute external page while doing some function with php?在使用 php 执行某些功能时执行外部页面?
【发布时间】:2011-08-03 18:42:39
【问题描述】:

您好,我正在尝试创建一个简单的脚本,该脚本将使用 WHM 在我的专用服务器上创建一个帐户 这是简单的代码

<?php

// your WHM username
$whm_user = 'root';

// your WHM password
$whm_pass = 'pass';

// your WHM hostname
$whm_host = '10.10.10.10';

// new account domain or subdomain name
$user_domain = 'example.com';

// new account username (8 characters or less)
$user_name = 'example';

// new account password
$user_pass = 'example1245';

// new account contact email
$user_email = 'user@example.net';

// new account plan (must be an existing WHM plan)
$user_plan = 'Gold';

// create the account
$site = "https://{$whm_user}:{$whm_pass}@{$whm_host}:2087/scripts/wwwacct";
$params = "?plan={$user_plan}";
$params .= "&domain={$user_domain}";
$params .= "&username={$user_name}";
$params .= "&password={$user_pass}";
$params .= "&contactemail={$user_email}";
$url = $site.$params; 
file_get_contents($url);
?>

这会返回一个错误

[function.file-get-contents]: failed to open stream: No error in C:\AppServ\www\cp\create-whm-account.php on line 35

然后我尝试使用 CURL

<?php

// your WHM username
$whm_user = 'root';

// your WHM password
$whm_pass = 'pass';

// your WHM hostname
$whm_host = '10.10.10.10';

// new account domain or subdomain name
$user_domain = 'example.com';

// new account username (8 characters or less)
$user_name = 'example';

// new account password
$user_pass = 'example1245';

// new account contact email
$user_email = 'user@example.net';

// new account plan (must be an existing WHM plan)
$user_plan = 'Gold';

// create the account
$site = "https://{$whm_user}:{$whm_pass}@{$whm_host}:2087/scripts/wwwacct";
$params = "?plan={$user_plan}";
$params .= "&domain={$user_domain}";
$params .= "&username={$user_name}";
$params .= "&password={$user_pass}";
$params .= "&contactemail={$user_email}";
$url = $site.$params; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
$data = curl_exec($ch); 
curl_close($ch); 
?>

它不返回任何错误,也不工作 我不需要返回任何输出,因为这将在其他函数中工作,所以我不需要显示任何结果,只需在后台创建帐户即可

【问题讨论】:

    标签: php cpanel whm


    【解决方案1】:

    我注意到您正在请求一个 HTTPS URL。可能需要额外的 CURL 标志。很有可能:

    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  2); 
    

    另见:PHP:Curl to fetch html page from HTTPS

    【讨论】:

    • 谢谢,但即使尝试回显输出也没有任何意义
    • 你尝试过额外的标志吗?没有它,HTTPS 将无法工作。
    猜你喜欢
    • 2014-01-03
    • 2019-10-16
    • 1970-01-01
    • 1970-01-01
    • 2017-03-27
    • 2019-03-21
    • 2021-09-06
    • 2016-04-03
    • 1970-01-01
    相关资源
    最近更新 更多