2

Possible Duplicate:
PHP: Can CURL follow meta redirects

<?php  
error_reporting(E_ALL);  
ini_set("display_errors", 1);    
$ch = curl_init();  
curl_setopt($ch, CURLOPT_URL, 'http.....');   
curl_setopt($ch,CURLOPT_POST,1);  
curl_setopt($ch, CURLOPT_HEADER,1);  
curl_setopt($ch, CURLINFO_HEADER_OUT,1);  
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);  
curl_setopt($ch,CURLOPT_AUTOREFERER,0);  
curl_setopt($ch,CURLOPT_POSTFIELDS,"vb_login_username=***&vb_login_password=***&do=login");  
curl_exec($ch);  
curl_close($ch);  
?>  

I want to login to a vbuletin forum. This login script works (it show the login success dialog), but after seconds, it redirects to the index page. I knew the problem, that is:

<META HTTP-EQUIV="refresh" CONTENT="seconds;URL=the-other-url">` 

I need a solution to stop this :D

Community
  • 1
  • 1
cdxf
  • 5,501
  • 11
  • 50
  • 65
  • It looks like a server side redirect, Nothing you could do unless you find a hack to make the vbulletin belive that your curl script is a browser and performing a valid operation! – Eswar Rajesh Pinapala Jun 22 '12 at 06:54
  • I don't think so, because i got the contents from the curl_Exec(); and when i login normally, it still redirect, so i think there are some ways to stop this. – cdxf Jun 22 '12 at 06:57
  • Its possible that this is because the lack of cookies. You are logging in alright, but no session is maintained. You need to set Curl cookies! – Eswar Rajesh Pinapala Jun 22 '12 at 07:00
  • I saw the problem, see my update post :D – cdxf Jun 22 '12 at 07:01
  • 1
    kewl! just do str_replace('', "",$curlResponse); where $curlResponse = curl_exec($ch); – Eswar Rajesh Pinapala Jun 22 '12 at 07:04
  • Frankly speaking, I'm yet to understand what you're trying to do. It's a kind of usual practice for `login.php` to generate a page with redirect for people who did supply the correct login/password. How this login page for logged people could be of interest to you? ) – raina77ow Jun 22 '12 at 07:08
  • I suppose it's actually an opposite of this question: 'can CURL _not_ follow meta redirects'. ) – raina77ow Jun 22 '12 at 07:39
  • @raina77ow: Yes, that's for reference that curl is not following the redirect here. Bringing it to the point that the question makes not much sense in it's current form. We can't stop curl from doing things it does not do. – hakre Jun 22 '12 at 07:41

1 Answers1

0

You can use

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

and you can get response $response = curl_exec($ch);

Miqdad Ali
  • 6,129
  • 7
  • 31
  • 50