Log in manually in the website and check what is exactly posted through the Browsers Network monitor. Maybe there is a simple typo in your parameters? You can open the Network monitor with F12 (Google CHrome or IE). Then start logging by pressing the appropriate button (make sure it preserves the log when a new page is loaded) and watch the entries roll by. Then login and see what is logged by opening the detailed view and watch the headers and response.
It is important that you start logging the HTTP requests before loading the login page. Sometimes a cookie is created before you login. That could give you a hint of what to send.
Remember that cookies need to be sent manually when not using a browser. So when you are logged on, remember to be sending additional information like cookies when using CURL.
Cookies are created but having a look at the network monitor is sends more parameters:
return_url=&action=login&username=emp&password=emp
Try this:
<?php
$username = 'emp';
$pass = 'emp';
$login = array(
'username' => $username,
'password' => $pass,
'action' => 'login',
'return_url' => '/my-account/'
);
$loginUrl = 'http://demo.smartjobboard.com/login';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_URL, $loginUrl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($login));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
$content1 = curl_exec($ch);
curl_setopt($ch, CURLOPT_URL, "http://demo.smartjobboard.com/my-account/");
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
$content2 = curl_exec($ch);
curl_close($ch);
echo $content2;
?>
This works; try it from a command line if you can. However, a status 303 (see other locatoin) is returned. Retrieving cookies can be done using CURL's option CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE. Have a look at the manual.
So you need to manually do another curl call probably, sending the received cookie.
Notice the extra options to retrieve the full verbose headers to learn what's happening!
My response:
HTTP/1.1 303 See Other
Server: nginx
Date: Fri, 06 Feb 2015 15:53:16 GMT
Content-Type: text/html;charset=utf-8
Content-Length: 0
Connection: keep-alive
Keep-Alive: timeout=35
X-Powered-By: PHP/5.3.28
Set-Cookie: PHPSESSID=b33b1a0bd7a3bcd50e5e73671c383182; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: PHPSESSID=baf0d249c8fd7795fa1234cbaf16995e; path=/
Location: http://demo.smartjobboard.com/my-account/
and
* Hostname was NOT found in DNS cache
* Trying 96.30.31.40...
* Connected to demo.smartjobboard.com (96.30.31.40) port 80 (#0)
> POST /login HTTP/1.1
Host: demo.smartjobboard.com
Accept: */*
Content-Length: 66
Content-Type: application/x-www-form-urlencoded
* upload completely sent off: 66 out of 66 bytes
< HTTP/1.1 303 See Other
* Server nginx is not blacklisted
< Server: nginx
< Date: Fri, 06 Feb 2015 15:53:16 GMT
< Content-Type: text/html;charset=utf-8
< Content-Length: 0
< Connection: keep-alive
< Keep-Alive: timeout=35
< X-Powered-By: PHP/5.3.28
< Set-Cookie: PHPSESSID=b33b1a0bd7a3bcd50e5e73671c383182; path=/
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
< Set-Cookie: PHPSESSID=baf0d249c8fd7795fa1234cbaf16995e; path=/
< Location: http://demo.smartjobboard.com/my-account/
<
* Connection #0 to host demo.smartjobboard.com left intact
(location is a bit garbled, but don't know why). Redirect location = http://demo.smartjobboard.com/my-account/. But you should parse the output to detect this address, so it works for other locations as well.
And I learned something as well ;).