Coś nie działa ten CURLOPT_FOLLOWLOCATION
Kod
PHP Error Message
Warning: curl_setopt() [function.curl-setopt]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set in /home/a8236701/public_html/test.php on line 19
Free Web Hosting
HTTP/1.1 302 Found Status: 302 Moved Set-Cookie: aff=3734; domain=.ryushare.com; path=/; expires=Fri, 19-Oct-2012 11:06:16 GMT Set-Cookie: login=c4ld3ra; domain=.ryushare.com; path=/; expires=Mon, 18-Mar-2013 11:06:16 GMT Set-Cookie: xfss=atah4zvai0gmy4zo; domain=.ryushare.com; path=/; expires=Fri, 19-Oct-2012 11:06:16 GMT Date: Wed, 19 Sep 2012 11:06:16 GMT Location: http://ryushare.com/ Connection: close Transfer-Encoding: chunked Server: Ryushare Webserver
Znalazłem w sieci funkcjie umożliwiającą automatyczne przekierowania, po jej zastosowaniu nadal brak oczekiwanego efektu.
<?php
function curl_exec_follow(/*resource*/ $ch, /*int*/ &$maxredirect = null) {
$mr = $maxredirect === null ? 5
: intval($maxredirect); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, $mr > 0);
curl_setopt($ch, CURLOPT_MAXREDIRS, $mr);
} else {
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
if ($mr > 0) {
$newurl = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$rch = curl_copy_handle($ch);
curl_setopt($rch, CURLOPT_HEADER, true);
#curl_setopt($rch, CURLOPT_NOBODY, true);
curl_setopt($rch, CURLOPT_FORBID_REUSE, false);
curl_setopt($rch, CURLOPT_RETURNTRANSFER, true);
do {
curl_setopt($rch, CURLOPT_URL, $newurl);
$header = curl_exec($rch);
if (curl_errno($rch)) {
$code = 0;
} else {
$code = curl_getinfo($rch, CURLINFO_HTTP_CODE);
if ($code == 301 || $code == 302) {
preg_match('/Location:(.*?)\n/', $header, $matches); } else {
$code = 0;
}
}
} while ($code && --$mr);
curl_close($rch);
if (!$mr) {
if ($maxredirect === null) {
# trigger_error('Too many redirects. When following redirects, libcurl hit the maximum amount.', E_USER_WARNING);
} else {
$maxredirect = 0;
}
return false;
}
curl_setopt($ch, CURLOPT_URL, $newurl);
}
}
return curl_exec($ch);
}
$login ="login";
$password = "haslo";
$op = "login";
$redirect = urlencode("http://ryushare.com/");
$c = curl_init();
curl_setopt($c,CURLOPT_URL,"http://ryushare.com/");
curl_setopt($c,CURLOPT_REFERER,"http://ryushare.com/login.python");
curl_setopt($c,CURLOPT_POST,1);
curl_setopt($c,CURLOPT_POSTFIELDS,"op=$op&redirect=$redirect&login=$login&password=$password");
curl_setopt($c,CURLOPT_RETURNTRANSFER,1);
$ret =curl_exec_follow($c);
curl_close($c);
# ok HTTP/1.1 200 OK Expires: Tue, 18 Sep 2012 11:01:13 GMT Date: Wed, 19 Sep 2012 11:01:13 GMT Content-Type: text/html; charset=UTF-8 Connection: close Server: Ryushare Webserver
?>