tags:

views:

337

answers:

2

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

A: 

It looks like you're both trying to save cookies to cookies.txt, and read them from there. What you would normally do is that the first url you visit, you have curl save the cookies to a file. Then, for subseqent requests, you supply that file.

I'm not sure of the php aspects, but from the curl aspects it looks like you're trying to read a cookie file that doesn't exist yet.

edit: oh, and if you're only doing one request, you shouldn't even need cookies.

Andrew B
A: 

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);
}
Sabeen Malik
it shows only javascript. page not randered. plesae help me
Sushant Panigrahi
i updated the post
Sabeen Malik