-1

Hello I am trying to login to the website bellow to get some data from there, I am trying to do this with cURL, I have tried multiple settings and mostly what I found here on this website, this is as closest as I have got. Because this code is the only one that so far can create the cookie file(it does not write anything in the cookie file but creates a file like coo8361.tmp each time the last 4 digits are random). I tried this on a simple form that I made and it's working just fine, it inserts some data into MySQL.

If you can give me any notes or information that I may use it would be very helpful.

Thank you

$username = '23434';
$password = 'sdfsfdsdf';


$ckfile = tempnam ("./", "cookie.txt"); 
$target_host = "http://www.somewebsite.com"; 
$target_request = "logon.html?ut=4";
$post_data = "action=LogonForm&username=$username&ownerPassword=$password";


$ch = curl_init ($target_host);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $ckfile); 
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec ($ch);

// 3. Continue
$login = curl_init ($target_host.$target_request);
curl_setopt($login, CURLOPT_COOKIESESSION, 1);
curl_setopt($login, CURLOPT_COOKIEJAR, $ckfile);
curl_setopt($login, CURLOPT_COOKIEFILE, $ckfile);
curl_setopt($login, CURLOPT_TIMEOUT, 40);
curl_setopt($login, CURLOPT_RETURNTRANSFER, 1);        
curl_setopt($login, CURLOPT_HEADER, 1);        
curl_setopt($login, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($login, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($login, CURLOPT_POST, 1);
curl_setopt($login, CURLOPT_POSTFIELDS, $post_data);
echo curl_exec($login);
curl_close($login);  
adrian7
  • 986
  • 12
  • 35
Natarau
  • 1
  • 1
  • possible duplicate of [Login to website using PHP and CURL](http://stackoverflow.com/questions/12450118/login-to-website-using-php-and-curl) – adrian7 Feb 02 '14 at 10:57

1 Answers1

0

Replace this

$login = curl_init ($target_host.$target_request);

with

$login = curl_init ($target_host."/".$target_request);
Sabuj Hassan
  • 38,281
  • 14
  • 75
  • 85
  • What is the original site? Try to run with debugging on `curl_setopt($login, CURLOPT_VERBOSE, true);` and what it returns? – Sabuj Hassan Feb 02 '14 at 16:30