我有卷发的问题,我不知道如何解决它们.
想法是获取用户的用户名和密码,并将其发布到外部网页.
这是代码:
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "https://sso.uc.cl/cas/login?service=https://portaluc.puc.cl/uPortal/Login"); // URL to post
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, "username=$usuario&password=$pw");
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec( $ch ); // runs the post
curl_close($ch);
echo "Reply Response: " . $result; // echo reply response
Run Code Online (Sandbox Code Playgroud)
这是错误:
Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/th000862/public_html/encuesta/login2.php on line 10
Run Code Online (Sandbox Code Playgroud)
在该错误之后,用户未登录到外部网页.
该错误意味着您的PHP配置禁止您访问该位置.有几种方法可以解决问题而无需安装@mario建议的其他库.
php_value safe_mode off.ini_set('safe_mode', false);PHP文件.如果以上都不起作用,您也可以沿着这些方向做一些事情:
$ch = curl_init('https://sso.uc.cl/cas/login?service=https://portaluc.puc.cl/uPortal/Login');
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'username=' . urlencode($usuario) . '&password=' . urlencode($pw));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_NOBODY, TRUE);
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
$result = curl_exec($ch);
curl_close($ch);
// Look to see if there's a location header.
if ( ! empty($result) )
if ( preg_match('/Location: (.+)/i', $result, $matches) )
{
// $matches[1] will contain the URL.
// Perform another cURL request here to retrieve the content.
}
Run Code Online (Sandbox Code Playgroud)