Attempting to enter a site with PHP and cURL?

I've never done anything like this before ... I'm trying to log into swagbucks.com and get some information, but it doesn't work. Can someone tell me what happened to my script?

<?php $pages = array('home' => 'http://swagbucks.com/?cmd=home', 'login' => 'http://swagbucks.com/?cmd=sb-login&from=/?cmd=home', 'schedule' => 'http://swagbucks.com/?cmd=sb-acct-account&display=2'); $ch = curl_init(); //Set options for curl session $options = array(CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; `rv:1.9.2) Gecko/20100115 Firefox/3.6',` CURLOPT_HEADER => TRUE, //CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_COOKIEFILE => 'cookie.txt', CURLOPT_COOKIEJAR => 'cookies.txt'); //Hit home page for session cookie $options[CURLOPT_URL] = $pages['home']; curl_setopt_array($ch, $options); curl_exec($ch); //Login $options[CURLOPT_URL] = $pages['login']; $options[CURLOPT_POST] = TRUE; $options[CURLOPT_POSTFIELDS] = ' emailAddress=lala@yahoo.com &pswd=jblake&persist=on'; $options[CURLOPT_FOLLOWLOCATION] = FALSE; curl_setopt_array($ch, $options); curl_exec($ch); //Hit schedule page $options[CURLOPT_URL] = $pages['schedule']; curl_setopt_array($ch, $options); $schedule = curl_exec($ch); //Output schedule echo $schedule; //Close curl session curl_close($ch); ?> 

But he still does not register me. What happened?

+4
source share
3 answers

try repeating each request to see if something went wrong. (inclusion of CURLOPT_RETURNTRANSFER)

+1
source

I suggest you use

 curl_setopt($ch, CURLOPT_COOKIEFILE, '/dev/null'); 

Thus, cookies are stored inside memory without the need for a shared file.

+1
source

It works for me with "persist = 1" and not "persist = on":

 $options[CURLOPT_POSTFIELDS] = ' emailAddress=lala@yahoo.com &pswd=jblake&persist=on'; // doesn't work $options[CURLOPT_POSTFIELDS] = ' emailAddress=lala@yahoo.com &pswd=jblake&persist=1'; // works $options[CURLOPT_POSTFIELDS] = ' emailAddress=lala@yahoo.com &pswd=jblake'; // also works 
0
source

Source: https://habr.com/ru/post/1304374/


All Articles