O ja tez zdążyłem zauważyć. Kombinowalem z curl i nie udaje mi się
Udało mi się wykrzesać taki kod:
Kod
<?
function curl_redirect_exec($ch, &$redirects, $curlopt_returntransfer = false, $curlopt_maxredirs = 10, $curlopt_header = false) {
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$exceeded_max_redirects = $curlopt_maxredirs > $redirects;
$exist_more_redirects = false;
if ($http_code == 301 || $http_code == 302) {
if ($exceeded_max_redirects) {
list($header) = explode("\r\n\r\n", $data, 2);
$matches = array();
preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches);
$url = trim(array_pop($matches));
$url_parsed = parse_url($url);
if (isset($url_parsed)) {
curl_setopt($ch, CURLOPT_URL, $url);
$redirects++;
return curl_redirect_exec($ch, $redirects, $curlopt_returntransfer, $curlopt_maxredirs, $curlopt_header);
}
}
else {
$exist_more_redirects = true;
}
}
if ($data !== false) {
if (!$curlopt_header)
list(,$data) = explode("\r\n\r\n", $data, 2);
if ($exist_more_redirects) return false;
if ($curlopt_returntransfer) {
return $data;
}
else {
echo $data;
if (curl_errno($ch) === 0) return true;
else return false;
}
}
else {
return false;
}
}
$url = "http://ipodzik.info/wp-login.php";
$pola = "log=$zmienna1&pwd=$zmienna2";
$f = curl_init();
curl_setopt($f, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($f, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($f, CURLOPT_USERAGENT, 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3');
curl_setopt($f, CURLOPT_URL, $url);
curl_setopt($f, CURLOPT_POSTFIELDS, $pola);
curl_setopt($f, CURLOPT_POST, 1);
curl_setopt($f, CURLOPT_HEADER, 0);
$redirects = 0; //Wykorzystanie funkcji powyżej - nie działa mi funkcja curl_redirect na serwerze
curl_redirect_exec($f, $redirects);
curl_setopt($f, CURLOPT_RETURNTRANSFER, 1);
$dane = curl_exec($f);
curl_close($f);
echo $dane;
?>
Niestety pomimo, iż sam skrypt działa, mam jeszcze problem ponieważ chcę aby adres zmienił się na prawidłowy (czyli adres admina skryptu

. Teraz jest tak, że po zalogowaniu adres w przeglądarce jest adresem skryptu A. Czy da radę to zmienić?