PHP/cURL-重定向并保持函数原来的位置
我使用以下代码/脚本:PHP/cURL-重定向并保持函数原来的位置,php,redirect,curl,Php,Redirect,Curl,我使用以下代码/脚本: <?php //Upload a blank cookie.txt to the same directory as this file with a CHMOD/Permission to 777 function login($url,$data){ $fp = fopen("cookie.txt", "w"); fclose($fp); $login = curl_init(); curl_setopt($login, CUR
<?php
//Upload a blank cookie.txt to the same directory as this file with a CHMOD/Permission to 777
function login($url,$data){
$fp = fopen("cookie.txt", "w");
fclose($fp);
$login = curl_init();
curl_setopt($login, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($login, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($login, CURLOPT_TIMEOUT, 40000);
curl_setopt($login, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($login, CURLOPT_URL, $url);
curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($login, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($login, CURLOPT_POST, TRUE);
curl_setopt($login, CURLOPT_POSTFIELDS, $data);
ob_start();
return curl_exec ($login);
ob_end_clean();
curl_close ($login);
unset($login);
}
function grab_page($site){
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_HTTPHEADER,array("Expect:"));
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_URL, $site);
ob_start();
return curl_exec ($ch);
ob_end_clean();
curl_close ($ch);
}
function post_data($site,$data,$data){
$datapost = curl_init();
$headers = array("Expect:");
curl_setopt($datapost, CURLOPT_URL, $site);
curl_setopt($datapost, CURLOPT_TIMEOUT, 40000);
curl_setopt($datapost, CURLOPT_HEADER, FALSE);
curl_setopt($datapost, CURLOPT_HTTPHEADER, $headers);
curl_setopt($datapost, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($datapost, CURLOPT_POST, TRUE);
curl_setopt($datapost, CURLOPT_POSTFIELDS, $data);
curl_setopt($datapost, CURLOPT_COOKIEFILE, "cookie.txt");
ob_start();
return curl_exec ($datapost);
ob_end_clean();
curl_close ($datapost);
unset($datapost);
}
?>
此脚本在另一个网站上的我的vps中运行,并完成一些自动功能。我想在执行该功能后重定向他留在我的vps上的原始网站
示例:我的代码/脚本的工作方式与google.com/page1类似,将函数自动执行到第4页,当我使用重定向时,他会再次启动到google.com/page1,而我想在重定向时保留第4页
原始网站是否有自动刷新功能
对不起,英语不好。您可以使用curl\u getinfo()
示例:
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_HTTPHEADER,array("Expect:"));
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_URL, $site);
ob_start();
curl_exec ($ch);
$last_redirected_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
ob_end_clean();
curl_close ($ch);
echo $last_redirected_url;
你总是大喊大叫吗?什么?我听不懂你说什么?请举个例子好吗?echo curl_getinfo($ch,);就这个?我不需要任何其他东西?谢谢你的脚本,但我是php curl的新手。。如果我有完整的例子,我知道如何使用。。请我的意思是我需要在这个脚本中添加我的网站?或者我需要在哪里替换?您的代码只是函数而不是主脚本,所以我无法帮助您。
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
curl_setopt($ch, CURLOPT_HTTPHEADER,array("Expect:"));
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_URL, $site);
ob_start();
curl_exec ($ch);
$last_redirected_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
ob_end_clean();
curl_close ($ch);
echo $last_redirected_url;