php怎么模拟post数据,然后保存cookie在客户端 php怎么模拟post数据,然后保存cookie在客户端,就是说模拟post登陆网站,然后点击跳转到其它页面时处于登陆状态的! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 先帐号密码md5验证,验证通过后,然后创建cookie,然后保存cookie,其他页面设定如果有这个cookie值就转入登录状态。 同一个网站的不同页面。如果服务器条件允许,建议使用SESSION。不同网站的可以通过其他方式时间多点同步登录。比如UCENTER。使用COOKIE保存数据时,COOKIE的路径参数建议手写,不要用默认。用默认的话,稍不注意就会出现,路径错误导致COOKIE无法读写的情况。 /** * 向指定网址发送post请求 * @parem $url * @parem $params * @return array */ function _post_request($url, $query_str) { if ( function_exists('curl_init') && USE_CURL===true ) { $ch = curl_init(); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POSTFIELDS, $query_str); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla-ylmf-u-api-cli (curl) '.phpversion() ); $result = curl_exec($ch); $errno = curl_errno($ch); curl_close($ch); //echo " $url & $query_str <hr /> $errno , $result "; return array($errno, $result); } else { $context = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded'."\r\n". 'User-Agent: Mozilla-ylmf-u-api-cli (non-curl) '.phpversion()."\r\n". 'Content-length: ' . strlen($query_str), 'content' => $query_str)); $contextid = stream_context_create($context); $sock = fopen($url, 'r', false, $contextid); if ($sock) { $result = ''; while (!feof($sock)) { $result .= fgets($sock, 4096); } fclose($sock); } } return array(0, $result); }至于增加cookie的header,我这里就不多说了 你是想在当前网站用php模拟让客户登录去另一个网站吧,可以明白告诉你:这是不可能的 curlfile_get_content()scoket都可以模拟!!谢谢! $_SERVER['REMOTE_HOST']问题!求大牛指导一二 请问为什么无法查询php中数据库记录? 懂php mvc开发的进来 急!急!小问题! 如何把Base64编码存的图,解码以后的结果保存成图,存在内存里?或者把图直接显示在浏览器上? myeclipse 开发 调试 php 无重复编号 通过html传递过来的参数,php查询 access 操作excel的问题,请高手指教! 在98下配置PWS+PHP4.0的问题 小鸟问问题。。 selected 标签 在修改页面中接收参数的问题。 关于Smarty 的问题
* 向指定网址发送post请求
* @parem $url
* @parem $params
* @return array
*/
function _post_request($url, $query_str)
{
if ( function_exists('curl_init') && USE_CURL===true )
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_str);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla-ylmf-u-api-cli (curl) '.phpversion() );
$result = curl_exec($ch);
$errno = curl_errno($ch);
curl_close($ch);
//echo " $url & $query_str <hr /> $errno , $result ";
return array($errno, $result);
}
else
{
$context =
array('http' =>
array('method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded'."\r\n".
'User-Agent: Mozilla-ylmf-u-api-cli (non-curl) '.phpversion()."\r\n".
'Content-length: ' . strlen($query_str),
'content' => $query_str));
$contextid = stream_context_create($context);
$sock = fopen($url, 'r', false, $contextid);
if ($sock)
{
$result = '';
while (!feof($sock))
{
$result .= fgets($sock, 4096);
}
fclose($sock);
}
}
return array(0, $result);
}至于增加cookie的header,我这里就不多说了
file_get_content()
scoket都可以模拟!!谢谢!