如何设置cookie的卷曲 [英] how can i set cookie in curl
问题描述
我正在获取somesite页面。
但不显示
和url地址更改。
例如我输入了
http: //localhost/sushant/EXAMPLE_ROUGH/curl.php
在curl页面我的编码是=
$ fp = fopen(cookie.txt,w);
fclose($ fp);
$ agent ='Mozilla / 5.0(Windows; U; Windows NT 5.1; pl; rv:1.9)Gecko / 2008052906 Firefox / 3.0';
$ ch = curl_init();
curl_setopt($ ch,CURLOPT_USERAGENT,$ agent);
// 2.设置选项,包括url
curl_setopt($ ch,CURLOPT_URL,http://www.fnacspectacles.com/place-spectacle/manifestation/Grand-spectacle -LE-ROI-LION-ROI4.htm);
curl_setopt($ ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ ch,CURLOPT_HEADER,0);
curl_setopt($ ch,CURLOPT_COOKIEJAR,'cookie.txt');
curl_setopt($ ch,CURLOPT_COOKIEFILE,cookie.txt);
// 3.执行并获取生成的HTML输出
if(curl_exec($ ch)=== false)
{
echo'Curl error: 。 curl_error($ ch);
}
else
echo $ output = curl_exec($ ch);
// 4.释放curl句柄
curl_close($ ch);
但它canege url这样..
http://localhost/aide.do?sht = _aide_cookies_
$如何解决这些问题帮助我
似乎在输出中有javascript,导致重定向。
所以为了测试目的,而不是使用:
echo $ output = curl_exec($ ch);
使用:
code> $ output = curl_exec($ ch);
echo strip_tags($ output);
更新:
if( curl_exec($ ch)=== false)
{
echo'Curl error:'。 curl_error($ ch);
}
else {
$ output = curl_exec($ ch);
$ fp2 = fopen(content.htm,w);
fwrite($ fp2,$ output);
fclose($ fp2);
}
i am fetching somesite page..
but it display nothing and url address change.
example i have typed
http://localhost/sushant/EXAMPLE_ROUGH/curl.php
in curl page my coding is=
$fp = fopen("cookie.txt", "w");
fclose($fp);
$agent= 'Mozilla/5.0 (Windows; U; Windows NT 5.1; pl; rv:1.9) Gecko/2008052906 Firefox/3.0';
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
// 2. set the options, including the url
curl_setopt($ch, CURLOPT_URL, "http://www.fnacspectacles.com/place-spectacle/manifestation/Grand-spectacle-LE-ROI-LION-ROI4.htm");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
// 3. execute and fetch the resulting HTML output
if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
echo $output = curl_exec($ch);
// 4. free up the curl handle
curl_close($ch);
but it canege url like this..
http://localhost/aide.do?sht=_aide_cookies_
object not found.
how can solve these problem help me
Seems like there is javascript in the output, which is causing the redirect.
So for testing purpose, instead of using:
echo $output = curl_exec($ch);
Use:
$output = curl_exec($ch);
echo strip_tags($output);
Update:
The code below will put the contents into contents.htm .. everything u need for pasring should be in there and in the output variable.
if(curl_exec($ch) === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else{
$output = curl_exec($ch);
$fp2 = fopen("content.htm" , "w");
fwrite($fp2 , $output);
fclose($fp2);
}
这篇关于如何设置cookie的卷曲的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!