-1

I've been trying to log into a site (www.namemc.com/login) with a curl script for about 5 hours now and I think I'm going crazy trying to do so.

I was wondering if you would be able to check what's wrong with my code. I think the site may be blocking it somehow, but I'm not sure.

Code:

<?php
$username = 'example@gmail.com';
$password = 'example';

$accountUrl = 'https://namemc.com/login';

$postdata = "email=".$username."&password=".$password; 

$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_NOBODY, 0);
curl_setopt($ch, CURLOPT_URL, $accountUrl);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_USERAGENT,
    "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);

$result = curl_exec($ch);

echo $result;
?>
Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • Please prefer : http://stackoverflow.com/questions/3008817/login-to-remote-site-with-php-curl – Dharmendra Sep 26 '16 at 07:43
  • Why using POST as your CURLOPT_CUSTOMREQUEST but formating your arguments like a GET request would expect ? – rak007 Sep 26 '16 at 07:44

1 Answers1

0

curl is a tool to transfer data from or to a server. The command is designed to work without user interaction.

You should be using either a cookie or a Header to maintain a session in your code like:

 cookie="cookie.txt"; 
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);

Also have you tried arguements in double quotes instead of single . and ensure send all form data which is needed in $postdata.

khakishoiab
  • 9,673
  • 2
  • 16
  • 22