Page 1 of 1
POST with cURL
Posted: Fri Jul 13, 2007 9:53 pm
by phoenix786
Hello all, I'm having a little trouble using cURL to get access to a search engine. To use the search engine you have to have a username and password. I've been trying to use cURL to automatically get access to the search engine by just going to the php page, but it's not working correctly.
Here's the link to the login page:
REALLY LONG URL
Here's my code:
Code: Select all
<?php
$username = "yourusername";
$password = "password";
$data = "myUserid=$username&myPassword=$password&_account=idd&_ver=5&group_". "id=&custom_id=&blnFromLogin=True&UID=ACFD2C48-37FC-464B-94D5-B71A5C0D942F&". "strUserName=&org_id=oc&lid=0&_ver=5&menus=99&dropdowns=&mls_property_id=&". "PreviousPage=%2Fsearch.asp%3F_org_id%3DOC%26_agent_public_id%3DF207052147%". "26_sponsor_office_id%3DF2918001%26_lid%3D0&parentURL=&_vp_cb=&_per_id=". "AC03501440044B2597862C35FABACDB2&_sponsor_org_id=oc&_sponsor_office_id=F2918001". "&agent_public_id=F207052147&SUBMIT1=Submit";
$referer = "http://www.searchpoint.net/my_login.asp?blnNewLogin=True&_account=idd&_org_id=oc&'. '_per_id=AC03501440044B2597862C35FABACDB2&_agent_public_id=F207052147&_lid=0&_menus=99'. '&_ver=5&_mls_property_id=&_current=&_ssid=1&PreviousPage=%2Fsearch%2Easp%3F%5Forg%5'. 'Fid%3DOC%26%5Fagent%5Fpublic%5Fid%3DF207052147%26%5Fsponsor%5Foffice%'. '5Fid%3DF2918001%26%5Flid%3D0";
$URL="www.searchpoint.net/my_login.asp";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://$URL");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURL_HEADER, TRUE);
curl_setopt($ch, CURLOPT_REFERER, $referer);
$result = curl_exec ($ch);
curl_close ($ch);
print $result;
?>
Any help would be appreciated.
Thank you,
-phoenix786
Posted: Fri Jul 13, 2007 9:56 pm
by DaveTheAve
Hello, normally when it comes to logging into a site there has to be a token on the client side that says who the client is.... What do I mean? I mean your not handling the cookie that says your logged-in..... there is a cURL parameter that will handle the cookie auth... I suggest you investigate there.
Posted: Sun Jul 15, 2007 10:53 pm
by afbase
Hey, I'm helping phoenix786 with this project. I'm not sure if what i'm posting is the "token". If it is what option should i use to pass it?
Code: Select all
$data = array('myUserid'=>urlencode('user'),
'myPassword'=>urlencode('pass'),
'_account'=>urlencode('idd'),
'_ver'=>urlencode('5'),
'group_id'=>urlencode(''),
'custom_id'=>urlencode(''),
'blnFromLogin'=>urlencode('True'),
'UID'=>urlencode('9905E3B2-7997-44D6-B982-3F348141123A'),
'strUserName'=>urlencode(''),
'org_id'=>urlencode('oc'),
'lid'=>urlencode('0'),
'_ver'=>urlencode('5'),
'menus'=>urlencode('99'),
'dropdowns'=>urlencode(''),
'mls_property_id'=>urlencode(''),
'PreviousPage'=>urlencode('/search.asp?_org_id=OC&_agent_public_id=F207052147&_sponsor_office_id=F2918001&_lid=0'),
'parentURL'=>urlencode(''),
'_vp_cb'=>urlencode(''),
'_per_id'=>urlencode('AC03501440044B2597862C35FABACDB2'),
'_sponsor_org_id'=>urlencode('oc'),
'_sponsor_office_id'=>urlencode('F2918001'),
'agent_public_id'=>urlencode('F207052147'),
'SUBMIT1'=>urlencode('Submit'));
Posted: Mon Jul 16, 2007 7:24 am
by Begby
Look in the documentation for 'curl cookie'. You will need to send the cookie with a seperate curl command. That is the token he is talking about.
Posted: Mon Jul 16, 2007 12:04 pm
by afbase
according to my firefox live httpheaders extension this is my what my "cookie" is
HTTP/1.x 302 Object moved
Date: Mon, 16 Jul 2007 16:35:38 GMT
Server: Microsoft-IIS/6.0
IISExport: This web site was exported using IIS Export v4.1
P3P: CP='CAO DSP COR CUR TAI PSA PSD IVA IVD CON HIS TEL OUR DEL SAM BUS OTC'
X-Powered-By: ASP.NET
Location: /search.asp?_logoff=1&_org_id=OC&_agent_public_id=F207052147&_sponsor_office_id=F2918001&_lid=0
Content-Length: 232
Content-Type: text/html
Set-Cookie: SESSION%5FSETTINGS=FIRST%5FNAME=Omar&USER%5FID=socal-search%40mailinator%2Ecom&
UID=161225C4%2D6D4B%2D433D%2DAD7D%2D558738A83043&AUTO%5FLOGIN=1; domain=
www.searchpoint.net; path=/
Set-Cookie: ACCOUNT%5FSETTINGS=FIRST%5FNAME=Omar&EMAIL%5FADDRESS=&LAST%5FNAME=Sheikh&
USER%5FID=socal-search%40mailinator%2Ecom&AUTO%5FLOGIN=1; expires=Fri, 01-Jan-2010 08:00:00 GMT; domain=
www.searchpoint.net; path=/
Set-Cookie: UID=161225C4%2D6D4B%2D433D%2DAD7D%2D558738A83043; expires=Fri, 01-Jan-2010 08:00:00 GMT; domain=
www.searchpoint.net; path=/
Cache-Control: private
i put that cookie into the curlopt_cookie but i get the same result page. I ask you guys to try the php code below, it should be working, and then you might see what problem i'm having. Even passing the cookie i have, I don't get the result i want. any ideas of what i should be doing or what i'm doing wrong?
the page that returns isn't what i want, I expect a page that gives me a form to enter more data in.
Code: Select all
<?php
$data = array('myUserid'=>urlencode('socal-search@mailinator.com'),
'myPassword'=>urlencode('vogon'),
'_account'=>urlencode('idd'),
'_ver'=>urlencode('5'),
'group_id'=>urlencode(''),
'custom_id'=>urlencode(''),
'blnFromLogin'=>urlencode('True'),
'UID'=>urlencode('9905E3B2-7997-44D6-B982-3F348141123A'),
'strUserName'=>urlencode(''),
'org_id'=>urlencode('oc'),
'lid'=>urlencode('0'),
'_ver'=>urlencode('5'),
'menus'=>urlencode('99'),
'dropdowns'=>urlencode(''),
'mls_property_id'=>urlencode(''),
'PreviousPage'=>urlencode('/search.asp?_org_id=OC&_agent_public_id=F207052147&_sponsor_office_id=F2918001&_lid=0'),
'parentURL'=>urlencode(''),
'_vp_cb'=>urlencode(''),
'_per_id'=>urlencode('AC03501440044B2597862C35FABACDB2'),
'_sponsor_org_id'=>urlencode('oc'),
'_sponsor_office_id'=>urlencode('F2918001'),
'agent_public_id'=>urlencode('F207052147'),
'SUBMIT1'=>urlencode('Submit'));
//echo http_build_query($data);
$cookie = 'SESSION%5FSETTINGS=FIRST%5FNAME=Omar&USER%5FID=kpx786%40yahoo%2Ecom&UID='. '161225C4%2D6D4B%2D433D%2DAD7D%2D558738A83043&AUTO%5FLOGIN=1; domain=www.searchpoint.net; path=/';
$cookie .= ' ACCOUNT%5FSETTINGS=FIRST%5FNAME=Omar&EMAIL%5FADDRESS=&LAST%5FNAME=Sheikh'. '&USER%5FID=kpx786%40yahoo%2Ecom&AUTO%5FLOGIN=1; expires=Fri, 01-Jan-2010 08:00:00 GMT; domain=www.searchpoint.net; path=/';
$cookie .= ' UID=161225C4%2D6D4B%2D433D%2DAD7D%2D558738A83043; expires=Fri, 01-Jan-2010 08:00:00 GMT; domain=www.searchpoint.net; path=/';
//$query = "myUserid=kpx786%40yahoo.com&myPassword=trivalley&_account=idd&_ver=5&group_id=&custom_id=&bln'. 'FromLogin=True&UID=8B695095-B743-4A42-8B23-48E856CF0623&strUserName=&org_id=oc&lid=0&_ver=5'. '&menus=99&dropdowns=&mls_property_id=&PreviousPage=%2Fsearch.asp%3F_logoff%3D1%26_logoff%3D1'. '%26_org_id%3DOC%26_agent_public_id%3DF207052147%26_sponsor_office_id%3DF2918001%26_lid%3D0&'. 'parentURL=&_vp_cb=&_per_id=AC03501440044B2597862C35FABACDB2&_sponsor_org_id=oc&_sponsor_office'. '_id=F2918001&agent_public_id=F207052147&SUBMIT1=Submit";
$query = "myUserid=socal-search%40mailinator.com&myPassword=vogon&_account=idd&_ver=5&group_id=&custom_id=&blnFro'. 'mLogin=True&UID=9905E3B2-7997-44D6-B982-3F348141123A&strUserName=&org_id=oc&lid=0&menus=99&dro'. 'pdowns=&mls_property_id=&PreviousPage=%252Fsearch.asp%253F_org_id%253DOC%2526_agent_public_id%2'. '53DF207052147%2526_sponsor_office_id%253DF2918001%2526_lid%253D0&parentURL=&_vp_cb=&_per_id=AC'. '03501440044B2597862C35FABACDB2&_sponsor_org_id=oc&_sponsor_office_id=F2918001&agent_public_id=F207052147&SUBMIT1=Submit";
$referer = urldecode("http://www.searchpoint.net/my_login.asp?blnNewLogin=True&_account=idd&_org_id=oc&_per_id=AC0'. '3501440044B2597862C35FABACDB2&_agent_public_id=F207052147&_lid=0&_menus=99&_ver=5&_mls_property'. '_id=&_current=&_ssid=1&PreviousPage=%2Fsearch%2Easp%3F%5Flogoff%3D1%26%5Flogoff%3D1%26%5Forg'. '%5Fid%3DOC%26%5Fagent%5Fpublic%5Fid%3DF207052147%26%5Fsponsor%5Foffice%5Fid%3DF2918001%26%5Flid%3D0");
$URL="http://www.searchpoint.net/my_login.asp";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_USERPWD, "socal-search@mailinator.com:vogon");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURL_HEADER, TRUE);
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
//print 'hello';
//curl_setopt($ch, CURLOPT_REFERER, $referer);
$result = curl_exec ($ch);
curl_close ($ch);
print $result;
?>
Posted: Tue Jul 17, 2007 2:30 am
by afbase
I'm at a dead end. Ok well we are submitting form information, $data, to the url, $URL, by way of cURL. The cURL should also download a page which is basically another form that I expect the user to use later on. I suspect that I need to collect a cookie that will be given to me while all this is happening, and pass it to the user that opens this php file. All this on a php 4.4 server (yes, i know your pain).
Code: Select all
<?php
session_start();
$data = array('myUserid'=>urlencode('socal-search@mailinator.com'),
'myPassword'=>urlencode('vogon'),
'_account'=>urlencode('idd'),
'_ver'=>urlencode('5'),
'group_id'=>urlencode(''),
'custom_id'=>urlencode(''),
'blnFromLogin'=>urlencode('True'),
'UID'=>urlencode('56058FA5-C934-4CFB-8322-80E112E9DF18'),
'strUserName'=>urlencode(''),
'org_id'=>urlencode('oc'),
'lid'=>urlencode('0'),
'_ver'=>urlencode('5'),
'menus'=>urlencode('99'),
'dropdowns'=>urlencode(''),
'mls_property_id'=>urlencode(''),
'PreviousPage'=>urlencode('/search.asp?_org_id=OC&_agent_public_id=F207052147&_sponsor_office_id=F2918001&_lid=0'),
'parentURL'=>urlencode(''),
'_vp_cb'=>urlencode(''),
'_per_id'=>urlencode('AC03501440044B2597862C35FABACDB2'),
'_sponsor_org_id'=>urlencode('oc'),
'_sponsor_office_id'=>urlencode('F2918001'),
'agent_public_id'=>urlencode('F207052147'),
'SUBMIT1'=>urlencode('Submit'));
$agent = "Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4";
$URL="http://www.searchpoint.net/my_login.asp";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, true);
//curl_setopt($ch, CURLOPT_USERPWD, "socal-search@mailinator.com:vogon");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($ch, CURL_HEADER, );
//curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie");
//print 'hello';
//curl_setopt($ch, CURLOPT_REFERER, $referer);
$result = curl_exec ($ch);
curl_close ($ch);
print $result;
print file_get_contents('cookie');
?>
please help me out here. Click
here for a demonstration of the php
Posted: Tue Jul 17, 2007 1:27 pm
by afbase
ok so my first step to this problem is obtaining the "cookie" information from "REALLY LONG URL" phoenix786 had described in the first post. Here is an example of that header information that is recieved when cURL'ing that url:
GET my_login.asp?blnNewLogin=True&_account=idd&_org_id=oc&_per_id=AC03501440044B2597862C35FABACDB2&_agent_public_id=F207052147
&_lid=0&_menus=99&_ver=5&_mls_property_id=&_current=&_ssid=1&PreviousPage=%2Fsearch%2Easp%3F%5Forg%5Fid%3DOC%26%
5Fagent%5Fpublic%5Fid%3DF207052147%26%5Fsponsor%5Foffice%5Fid%3DF2918001%26%5Flid%3D0 HTTP/1.1
Host:
http://www.searchpoint.net
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4
Accept: application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,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:
viewtopic.php?t=70685&highlight=
Cookie: SRCH=_account=idd&_sponsor_type=Agent&_account_id=oc_F207052147&_trace=0&_org_id=oc&_pType=1&_any_f=0&_any_l=0&state=ca&
_ver=5&_agent_email=
clinton.bowen@gmail.com&_menus=99&_adv_srch=0&_new=1&property_type=RES&_per_id=AC03501440044B2597862C3
5FABACDB2&_count=6&_lid=0&_sort_by=Case%20when%20agent_public_id%20IN%20('F207052147')%20then%200%20else%201%20end,Ca
se%20when%20agent_office_id%20IN%20('F2918001')%20then%200%20else%201%20end,list_price%20desc&_wpid=1&_save_srch=1&_client_n
ame=rumple%20stealskin&_ssid=1&_agent_public_id=F207052147&city_name=Agua%20Dulce&_sponsor_office_id=F2918001&_sponsor_org_id=
oc&_start=1&I:Baths:gte=2&_slog_type=1&_measuring_system=E; ACCOUNT%5FSETTINGS=FIRST%5FNAME=rumple&EMAIL%5FADDRESS=&LA
ST%5FNAME=stealskin&USER%5FID=socal%2Dsearch%40mailinator%2Ecom&AUTO%5FLOGIN=1; UID=56058FA5%2DC934%2D4CFB%2D8322%2D80E112E9DF18
Cache-Control: max-age=0
In the "Cookie:" i need to collect the UID value. I am not sure how to do this exactly this is what i have so far.
Code: Select all
<?php
$URL = "http://www.searchpoint.net/my_login.asp?blnNewLogin=True&_account=idd&_org_id=oc&_per_id=AC03501440044B2597862C35FABACDB2&_age'. 'nt_public_id=F207052147&_lid=0&_menus=99&_ver=5&_mls_property_id=&_current=&_ssid=1&PreviousPage=%2Fsearch%2Easp%3F%5Forg%5Fid%3D'. 'OC%26%5Fagent%5Fpublic%5Fid%3DF207052147%26%5Fsponsor%5Foffice%5Fid%3DF2918001%26%5Flid%3D0";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$URL);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 3);
//curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, "GET");
$result = curl_exec($ch);
curl_close($ch);
if (isset($_SESSION['UID'])){
print $_SESSION['UID'];
}
else{
print file_get_contents("GET");
}
?>