Jump to content

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

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.