Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 731
  • Last Modified:

php curl login example needed

Hi,

Can anyone post an example of how to login using curl?

here are the headers of the site im trying to login to:


http://www.domain.com/login.html

GET /login.html HTTP/1.1
Host: www.domain.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: __utma=120994266.85626791550490050.1234616112.1234616112.1234616112.1; __utmb=120994266.1.10.1234616112; __utmz=120994266.1234616112.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)
If-Modified-Since: Tue, 20 May 2008 19:18:35 GMT
If-None-Match: "2254f54caebac81:1f27"

HTTP/1.x 304 Not Modified
Last-Modified: Tue, 20 May 2008 19:18:35 GMT
Accept-Ranges: bytes
Etag: "2254f54caebac81:1f27"
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Sat, 14 Feb 2009 12:54:52 GMT
----------------------------------------------------------
http://www.domainshop.com/shopper_lookup.asp

POST /shopper_lookup.asp HTTP/1.1
Host: www.domainshop.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.domain.com/login.html
Content-Type: application/x-www-form-urlencoded
Content-Length: 66
shopper_username=MYUSERNAME&shopper_password=MYPASSWORD&Validate=1
HTTP/1.x 302 Object moved
Server: Microsoft-IIS/5.0
Date: Sat, 14 Feb 2009 13:01:48 GMT
COMMERCE-SERVER-SOFTWARE: Microsoft Commerce Server 2002
Location: contents.asp?ms=
Content-Length: 137
Content-Type: text/html
Set-Cookie: domain=mscssid=W3FBWE998Q1W9KU09VGENJVWLF500439; expires=Sun, 14-Mar-2010 13:01:48 GMT; path=/
Set-Cookie: ShopperManager%2F%2F=ShopperManager%2F%2F=W3FBWE998Q1W9KU09VGENJVWLF500439; expires=Fri, 01-Jan-2010 00:00:00 GMT; path=/
Cache-Control: private
----------------------------------------------------------
http://www.domainshop.com/contents.asp?ms=

GET /contents.asp?ms= HTTP/1.1
Host: www.domainshop.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.domain.com/login.html
Cookie: domain=mscssid=W3FBWE998Q1W9KU09VGENJVWLF500439; ShopperManager%2F%2F=ShopperManager%2F%2F=W3FBWE998Q1W9KU09VGENJVWLF500439

HTTP/1.x 200 OK
Server: Microsoft-IIS/5.0
Date: Sat, 14 Feb 2009 13:01:51 GMT
COMMERCE-SERVER-SOFTWARE: Microsoft Commerce Server 2002
Content-Length: 104208
Content-Type: text/html
Cache-Control: private
----------------------------------------------------------
http://www.domainshop.com/shops/cccdist/domain.css

GET /shops/cccdist/domain.css HTTP/1.1
Host: www.domainshop.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5
Accept: text/css,*/*;q=0.1
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.domainshop.com/contents.asp?ms=
Cookie: domain=mscssid=W3FBWE998Q1W9KU09VGENJVWLF500439; ShopperManager%2F%2F=ShopperManager%2F%2F=W3FBWE998Q1W9KU09VGENJVWLF500439

HTTP/1.x 200 OK
Server: Microsoft-IIS/5.0
COMMERCE-SERVER-SOFTWARE: Microsoft Commerce Server 2002
Date: Sat, 14 Feb 2009 13:01:51 GMT
Content-Type: text/css
Accept-Ranges: bytes
Last-Modified: Mon, 19 Jan 2009 15:27:24 GMT
Etag: "842d976d4a7ac91:b47"
Content-Length: 7054
----------------------------------------------------------
http://www.domainshop.com/shops/cccDist/images/new-top_01.jpg

GET /shops/cccDist/images/new-top_01.jpg HTTP/1.1
Host: www.domainshop.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.domainshop.com/contents.asp?ms=
Cookie: domain=mscssid=W3FBWE998Q1W9KU09VGENJVWLF500439; ShopperManager%2F%2F=ShopperManager%2F%2F=W3FBWE998Q1W9KU09VGENJVWLF500439

HTTP/1.x 200 OK
Server: Microsoft-IIS/5.0
COMMERCE-SERVER-SOFTWARE: Microsoft Commerce Server 2002
Date: Sat, 14 Feb 2009 13:01:51 GMT
Content-Type: image/jpeg
Accept-Ranges: bytes
Last-Modified: Mon, 19 Jan 2009 16:08:08 GMT
Etag: "62356e1e507ac91:b47"
Content-Length: 10400
----------------------------------------------------------
http://www.domainshop.com/shops/cccDist/images/quick.gif

GET /shops/cccDist/images/quick.gif HTTP/1.1
Host: www.domainshop.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.domainshop.com/contents.asp?ms=
Cookie: domain=mscssid=W3FBWE998Q1W9KU09VGENJVWLF500439; ShopperManager%2F%2F=ShopperManager%2F%2F=W3FBWE998Q1W9KU09VGENJVWLF500439

HTTP/1.x 200 OK
Server: Microsoft-IIS/5.0
COMMERCE-SERVER-SOFTWARE: Microsoft Commerce Server 2002
Date: Sat, 14 Feb 2009 13:01:51 GMT
Content-Type: image/gif
Accept-Ranges: bytes
Last-Modified: Thu, 27 Feb 2003 07:12:04 GMT
Etag: "f01eb1872fdec21:b47"
Content-Length: 1087
----------------------------------------------------------
http://www.domainshop.com/shops/cccdist/images/about.gif

GET /shops/cccdist/images/about.gif HTTP/1.1
Host: www.domainshop.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.domainshop.com/contents.asp?ms=
Cookie: domain=mscssid=W3FBWE998Q1W9KU09VGENJVWLF500439; ShopperManager%2F%2F=ShopperManager%2F%2F=W3FBWE998Q1W9KU09VGENJVWLF500439

HTTP/1.x 200 OK
Server: Microsoft-IIS/5.0
COMMERCE-SERVER-SOFTWARE: Microsoft Commerce Server 2002
Date: Sat, 14 Feb 2009 13:01:51 GMT
Content-Type: image/gif
Accept-Ranges: bytes
Last-Modified: Thu, 27 Feb 2003 07:11:49 GMT
Etag: "0b4c77e2fdec21:b47"
Content-Length: 831
----------------------------------------------------------
http://www.domainshop.com/shops/cccdist/images/home.gif

GET /shops/cccdist/images/home.gif HTTP/1.1
Host: www.domainshop.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5
Accept: image/png,image/*;q=0.8,*/*;q=0.5
Accept-Language: en-gb,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://www.domainshop.com/contents.asp?ms=
Cookie: domain=mscssid=W3FBWE998Q1W9KU09VGENJVWLF500439; ShopperManager%2F%2F=ShopperManager%2F%2F=W3FBWE998Q1W9KU09VGENJVWLF500439

HTTP/1.x 200 OK
Server: Microsoft-IIS/5.0
COMMERCE-SERVER-SOFTWARE: Microsoft Commerce Server 2002
Date: Sat, 14 Feb 2009 13:01:51 GMT
Content-Type: image/gif
Accept-Ranges: bytes
Last-Modified: Thu, 27 Feb 2003 07:11:57 GMT
Etag: "a0e7ec832fdec21:b47"
Content-Length: 523
----------------------------------------------------------

0
stuayre
Asked:
stuayre
1 Solution
 
Ionut A. TudorPHP ProgrammerCommented:
i've build you below an example, modify it to your needs. Cheers
<?php
 
$url = "http://example.com/login.php"; // the url where to send the request
$fields_send = 'login=yourusername&password=yourpassword&otherfield=fieldvalue';
$agent = "your browser signature";
$reffer = "the url you're comming from";
$cookie_file_path = "cookie"; // Cookie File Path with CHMOD 777
 
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_send);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_REFERER, $reffer);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file_path);
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file_path);
$result_source = curl_exec($ch);
curl_close($ch);
 
echo $result_source; // Print the result page
 
?>

Open in new window

0
 
stuayreAuthor Commented:
wow! that works like a dream!

cheers!!

Stu
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now