AbydosGater Posted June 2, 2007 Share Posted June 2, 2007 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 More sharing options...
chigley Posted June 2, 2007 Share Posted June 2, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.