Jump to content

Curl N00b questions.


AbydosGater

Recommended Posts

Hey guys. Ive been playing with some CURL. Getting to know it.. Thought it would be an idea to see if i can get it to log into my site for me.

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.mysite.com');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, "textfield=abydosgater&textfield2=MYPASS&Submit=true"); // add POST fields 
$data = curl_exec($ch);
echo $data;
curl_close($ch);

?> 

 

That worked quite well. and display my site for me when im logged in.

But i tried adding the following code to the end of my page to see if i could view my members area.

<?php
//Rest of other code posted above here!
echo "<hr>";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.my-sgc.com/members/chat/index.php');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_POST, 1); // set POST method
//curl_setopt($ch, CURLOPT_POSTFIELDS, "textfield=abydosgater&textfield2=4&Submit=true"); // add POST fields 
$data = curl_exec($ch);
echo $data;
curl_close($ch);
?> 

 

But that displays my warning page that the user is not logged in.

How come it says im not logged in, when the first code does it for me?

Am i doing something wrong?

 

Andy

Link to comment
https://forums.phpfreaks.com/topic/53926-curl-n00b-questions/
Share on other sites

Don't close then init again:

 

<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.mysite.com');
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, "textfield=abydosgater&textfield2=MYPASS&Submit=true"); // add POST fields 
$data = curl_exec($ch);

curl_setopt($ch, CURLOPT_URL, "http://www.my-sgc.com/members/chat/index.php");
$members = curl_exec($ch);
echo $members;

curl_close($ch);

?>

Link to comment
https://forums.phpfreaks.com/topic/53926-curl-n00b-questions/#findComment-266851
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.