Jump to content

Recommended Posts

Hi to everyone, I'm new to the forum and I'm posting here because I ended up in a logical problem for my next script development.

I need to get some data of external websites (with vbulletin board), perfectly legal.

Using file_get_contents i can print the page content on my server and then use jquery's powerful selectors to get my data.

 

The problem is that these data are shown only to logged in users so i would need this script (maybe using cURL?) to either login to the external website and then persists the connection or maybe if the user who is executing my script is already logged in that website then use his login? (most likely impossible I think..)

 

This is my code so far (found on some sites and merged into this)

$data = array('vb_login_username' => 'Scanu', 'vb_login_password' => 'grgfgrgrfbtgbt');
$ch = curl_init(); 
curl_setopt($ch,    CURLOPT_URL,            "http://www.vbulletin.org/forum/login.php?do=login"); 
curl_setopt($ch,    CURLOPT_AUTOREFERER,         true); 
curl_setopt($ch,    CURLOPT_COOKIESESSION,         true); 
curl_setopt($ch,    CURLOPT_FAILONERROR,         false); 
curl_setopt($ch,    CURLOPT_FOLLOWLOCATION,        false); 
curl_setopt($ch,    CURLOPT_FRESH_CONNECT,         true); 
curl_setopt($ch,    CURLOPT_HEADER,             true); 
curl_setopt($ch,    CURLOPT_POST,                 true); 
curl_setopt($ch,    CURLOPT_RETURNTRANSFER,        true); 
curl_setopt($ch,    CURLOPT_CONNECTTIMEOUT,     30); 
curl_setopt($ch,    CURLOPT_POSTFIELDS,         $data); 
$result = curl_exec($ch); 
curl_close($ch);


$pattern = "#Set-Cookie: (.*?; path=.*?;.*?)\n#"; 
preg_match_all($pattern, $result, $matches); 
array_shift($matches); 
$cookie = implode("\n", $matches[0]); 


$ch = curl_init(); 
curl_setopt($ch,    CURLOPT_URL,            "http://www.vbulletin.org/forum/"); 
curl_setopt($ch,    CURLOPT_COOKIE,                $cookie); 
curl_setopt($ch,    CURLOPT_AUTOREFERER,         true); 
curl_setopt($ch,    CURLOPT_COOKIESESSION,         true); 
curl_setopt($ch,    CURLOPT_FAILONERROR,         false); 
curl_setopt($ch,    CURLOPT_FOLLOWLOCATION,        false); 
curl_setopt($ch,    CURLOPT_FRESH_CONNECT,         true); 
curl_setopt($ch,    CURLOPT_HEADER,             false); 
curl_setopt($ch,    CURLOPT_POST,                 false); 
curl_setopt($ch,    CURLOPT_RETURNTRANSFER,        true); 
curl_setopt($ch,    CURLOPT_CONNECTTIMEOUT,     30); 
$result = curl_exec($ch); 
curl_close($ch);
echo $result;
?>

It just shows the same page for unregistered users. Any help or advice is appreciated, i'm very new to this type of script..

Edited by Scanu
Link to comment
https://forums.phpfreaks.com/topic/290377-curl-with-sessioncookie/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.