For a personal project, I'm trying to automate the download of a file from a website that I do not have control/access to. To download the file, user input is required on a total of 6 pages, each with a form submission with the download on the final page.
URL: https://www2.iris.gov.hk/eservices/searchlandregister/search.jsp
I've managed to use cURL to navigate through the first 3 pages. When my cURL code gets the 4th page, it gives me the following error:
"Cannot place order from multiple browser windows, please retry."
This error is generated by the server (not cURL) so I have no idea what it means or how to work around this problem. But if you manually submit the forms on each page, you can progress to the 4th page without error.
Here's the working code. You'll notice the first 3 pages work as expected. However, if you uncomment out the code for the forth page, you'll see that it generates the error message.
I'm stumped! Any help or suggestions would be greatly appreciated.
Thanks!
/**
* Page 1
*
* Sample input data:
*
* Floor: 62
* Flat No: D
* House No: 1
* Street Name: Austin Road West
* Area Code: Kowloon
*
*
*/
$cookie="cookie.txt";
$url = "https://www1.iris.gov.hk/eservices/searchlandregister/search.jsp";
$url2 = "https://www2.iris.gov.hk/eservices/searchLandRegister.do";
$url3 = "https://www2.iris.gov.hk/eservices/searchLandRegister.do";
$url4 = "https://www2.iris.gov.hk/eservices/searchByAddressResult2.do";
$params = array(
'previousOp' => urlencode(''),
'functionId' => urlencode('continue'),
'forward2Caller' => urlencode('searchlandregister'),
'SStreetName' => urlencode('eng'),
'SDevelopmentName' => urlencode('eng'),
'SBlock' => urlencode('*'),
'SFloor' => urlencode('62'),
'SFlat' => urlencode('D'),
'searchBySection' => urlencode('StreetName'),
'SSelectedArea' => urlencode('20'),
'SDevelopmentNameEng' => urlencode(''),
'SDevelopmentNameChn' => urlencode(''),
'SStreetNameEng' => urlencode('AUSTIN ROAD WEST'),
'SStreetNameChn' => urlencode(''),
'hasSpec' => urlencode('0'),
'hasLotSpec' => urlencode('0'),
'specPrn' => urlencode(''),
'haveSDR' => urlencode('Y'),
'initFromRVD' => urlencode('N'),
'SHouseNo1' => urlencode('1'),
'SHouseNo2' => urlencode(''),
'SPrn' => urlencode(''),
'SExtension' => urlencode('false'),
'SLotType' => urlencode(''),
'SLotNo' => urlencode(''),
'SSection1' => urlencode(''),
'SSub1' => urlencode(''),
'SSection2' => urlencode(''),
'SSub2' => urlencode(''),
'SSection3' => urlencode(''),
'SSub3' => urlencode(''),
'SSection4' => urlencode(''),
'SMisc' => urlencode(''),
'recordIndex' => urlencode(''),
'SSBlock' => urlencode('*'),
'SSFloor' => urlencode('62'),
'SSFlat' => urlencode('D'),
'SDBlock' => urlencode('*'),
'SDFloor' => urlencode('*'),
'SDFlat' => urlencode('*'),
'SLBlock' => urlencode('*'),
'SLFloor' => urlencode('*'),
'SLFlat' => urlencode('*'),
'SRegisterName' => urlencode('SDR'),
'SSRegisterName' => urlencode('SDR'),
'SLRegisterName' => urlencode('SDR'),
'SDRegisterName' => urlencode('SDR'),
'xSSBlock' => urlencode('*'),
'xSSFloor' => urlencode('62'),
'xSSFlat' => urlencode('D'),
'xHouseNo1' => urlencode('1'),
'xHouseNo2' => urlencode(''),
'SStreetNameInput' => urlencode('AUSTIN ROAD WEST'),
'xSelectedArea' => urlencode('20'),
'xSSRegisterName' => urlencode('SDR'),
'xSDBlock' => urlencode('*'),
'xSDFloor' => urlencode('*'),
'xSDFlat' => urlencode('*'),
'SDevelopmentNameInput' => urlencode(''),
'xSDRegisterName' => urlencode('SDR'),
'xSLBlock' => urlencode('*'),
'xSLFloor' => urlencode('*'),
'xSLFlat' => urlencode('*'),
'SLotTypeInput' => urlencode(''),
'xLotNo' => urlencode(''),
'xSection1' => urlencode(''),
'xSub1' => urlencode(''),
'xSection2' => urlencode(''),
'xSub2' => urlencode(''),
'xSection3' => urlencode(''),
'xSub3' => urlencode(''),
'xSection4' => urlencode(''),
'xMisc' => urlencode(''),
'xSLRegisterName' => urlencode('SDR'),
'xPrn' => urlencode(''),
// Page 2
'dispLotPRN' => urlencode('C5458863'),
'dispBlock' => urlencode('SO1'),
'BBlock' => urlencode('SO1'),
'hasBlock' => urlencode('1'),
// Page 3
'somePrn[0]' => urlencode('B6479113'),
'someSelected[0]' => urlencode('on'),
'someEnquiry[0]' => urlencode('C'),
'someNature[0]' => urlencode('P'),
'someCopies[0]' => urlencode('1'),
// Page 4
'dispHouseNo' => urlencode('1'),
'dispStreetName' => urlencode('AUSTIN ROAD WEST'),
'hasLot' => urlencode('0'),
'hasFloor' => urlencode('0'),
'street' => urlencode('true'),
'dev' => urlencode('false'),
'lot' => urlencode('false')
);
//url-ify the data for the POST
foreach($params as $key=>$value) {
$string .= $key.'='.$value.'&';
} // end foreach
rtrim($string, '&');
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($ch, CURLOPT_POST, false);
$result = curl_exec ($ch);
//echo $result;
// Submit to Page 2
curl_setopt ($ch, CURLOPT_URL, $url2 . '?' . $string);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($ch, CURLOPT_POST, false);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $params);
$result = curl_exec ($ch);
//echo $result;
// Submit to Page 3
$params['previousOp'] = 'BLOCK LIST';
curl_setopt ($ch, CURLOPT_URL, $url3 . '?' . $string);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($ch, CURLOPT_POST, false);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $params);
$result = curl_exec ($ch);
//echo $result;
// Submit to Page 4
/*
$params['previousOp'] = 'EXACT MATCH';
$params['functionId'] = 'doAddAndGoToOrder';
$params['queryResultHash'] = '978962765';
curl_setopt ($ch, CURLOPT_URL, $url4 . '?' . $string);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.109 Safari/537.36");
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt ($ch, CURLOPT_COOKIEJAR, $cookie);
curl_setopt ($ch, CURLOPT_COOKIEFILE, $cookie);
curl_setopt ($ch, CURLOPT_POST, 1);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $params);
$result = curl_exec ($ch);
*/
curl_close($ch);
echo $result;
Related
Im using the following code:
$json_link = "https://graph.facebook.com/v2.12/me?fields=id,picture.width(300).height(280)&access_token=".$accessToken."";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $json_link);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec($ch);
curl_close($ch);
$obj = json_decode($output);
$xx=$obj->picture->data->url;
$src=imagecreatefromstring(file_get_contents($xx));
$obj returns the following:
stdClass Object (
[id] => idxxxxx
[picture] => stdClass Object (
[data] => stdClass Object (
[height] => 480
[is_silhouette] =>
[url] => lookaside.facebook.com/platform/profilepic/
[width] => 415
)
)
)
But it is failing on:
$xx=$obj->picture->data->url;
$src=imagecreatefromstring(file_get_contents($xx));
I get:
So fails:
imagecreatefromstring(file_get_contents($xx));
It worked fine before March 27, but after graph api update its no longer working.
FB is looking for User-agent information.
$User_Agent = 'Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.43 Safari/537.31';
$request_headers = array();
$request_headers[] = 'User-Agent: '. $User_Agent;
$request_headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$r = curl_exec($ch);
curl_close($ch);
It will solve your problem.
Only put the line: file_put_contents('file.jpg', fopen($obj->picture->data->url, 'r'));
To restart my router I can access to web page at 192.168.1.1/tools.lp and click on the restart button.
This is the code of the page
<form name="gwRestart" method="post" action="restartingAG.lp">
<input type="hidden" name="action" id="restartAction" value="saveRestart" />
<table border='0' cellspacing='0' cellpadding='0' width='100%' style="text-align:center">
<tr>
<td>
<a href="javascript:document.gwRestart.submit();">
<div class="midarea7-1 mainButton">RESTART</div></a>
</td><td> </td>
</tr>
</table>
</form>
I would restart my router using a php page and I tried to do it with cURL in this way
$post_data['action'] = 'saveRestart';
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection
$ch = curl_init('http://192.168.1.1/restartingAG.lp');
//set options
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
//set data to be posted
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($ch);
//show information regarding the request
print_r(curl_getinfo($ch));
//echo curl_errno($ch) . '-' . curl_error($ch);
//close the connection
curl_close($ch);
Unfortunately, I noticed that my request is redirected to index_auth.lp (login function is disabled!) and not to that required.
Array ( [url] => http://192.168.1.1/index_auth.lp [content_type] => text/html [http_code] => 200 [header_size] => 858 [request_size] => 630 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 2 [total_time] => 1.216 [namelookup_time] => 0 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 7233 [speed_download] => 5948 [speed_upload] => 0 [download_content_length] => 7233 [upload_content_length] => 0 [starttransfer_time] => 0.53 [redirect_time] => 0.686 [redirect_url] => [primary_ip] => 192.168.1.1 [certinfo] => Array ( ) [primary_port] => 80 [local_ip] => 192.168.1.5 [local_port] => 50687 )
Perhaps because the request is from a different ip? Can I somehow make a request as if it were made by a user on the web page? Thanks
$post_data = array();
$post_data['action'] = 'saveRestart';
foreach ( $post_data as $key => $value) {
$post_items[] = $key . '=' . $value;
}
$post_string = implode ('&', $post_items);
$ch = curl_init('http://192.168.1.1/restartingAG.lp');
$headers = array();
$headers[] = "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$headers[] = "Cache-Control: max-age=0";
$headers[] = "Connection: keep-alive";
$headers[] = "Keep-Alive: 300";
$headers[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$headers[] = "Accept-Language: en-us,en;q=0.5";
$headers[] = "Pragma: ";
//set options
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_REFERER, 'http://192.168.1.1/tools.lp');
curl_setopt($ch, CURLOPT_COOKIEJAR, "my_cookies.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "my_cookies.txt");
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_string);
$result = curl_exec($ch);
curl_close($ch);
echo "<pre>";
echo $result;
From what i can, you are not to actually send your request as a POST request. Currently you are sending the message as a GET request, but with some post-data attached.
Your code is missing this line
curl_setopt($ch, CURLOPT_POST, 1);
I'm quite new in PHP but for practise I wanted to write a script using curl for logging and send post request to a page site written in asp. I've used libcurl and simple_html_dom.php libraries.
Sometimes I got an error for invalid viewstate, this is the stack trace:
[ViewStateException: Invalid viewstate.
Client IP: 111.11.11.111
Port: 4743
User-Agent: Mozilla/5.0
ViewState: /wEPDwUKLTk1OTAzODYwMA9kFgJmD2QWBAIBD2QWAgIBD2QWCmYPFgIeBFRleHQFRTxtZXRhIHByb3BlcnR5PSJvZzp0aXRsZSIgY29udGVudD0iQURJREFTIEVRVCBSVU5OSU5HIENVU0hJT04gOTEiIC8+IGQCAQ8WAh8ABWY8bWV0YSBwcm9wZXJ0eT0ib2c6aW1hZ2UiIGNvbnRlbnQ9Imh0dHA6Ly9zaG9wLnVyYmFuanVuZ2xlc3RvcmUuaXQvZm90b19hcnRpY29saS9kNjc1NjgtaW50cm8uanBnIiAvPiBkAgIPFgIfAAWVBDxtZXRhIHByb3BlcnR5PSJvZzpkZXNjcmlwdGlvbiIgY29udGVudD0iUmVjZW50ZW1lbnRlLCBvbHRyZSBhbGxlIG1pdGljaGUgU3RhbiBTbWl0aCwgc29ubyB0b3JuYXRlIGluIGF1Z2UgZGVpIHBlenppIGRlbGxhIHNlcmllIE9kZGl0eS4gTmVsIDIwMDUgYWRpZGFzIGhhIGxhbmNpYXRvIHVuYSBjb2xsZXppb25lIHNwZWNpYWxlIGRpIHJ1bm5lcnMgY29uIGFsY3VuaSBkZWkgY29sb3JpIHBpJnVncmF2ZTsgcGF6emkgY2hlIHNpIHBvc3Nhbm8gbWV0dGVyZSBzdSB1bmEgc25lYWtlci4gRSBtZW50cmUgcXVlc3RvIG1vZGVsbG8gZGkgYWRpZGFzIEVRVCBSdW5uaW5nIEN1c2hpb24gbm9uIGZhIHVmZmljaWFsbWVudGUgcGFydGUgZGVsIHJpdG9ybm8gZGVsbGEgY29sbGV6aW9uZSBPZGRpdHkgKG8gZm9yc2UgcyZpZ3JhdmU7PyksIGx...]
[HttpException (0x80004005): Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.
http://go.microsoft.com/fwlink/?LinkID=314055]
System.Web.UI.ViewStateException.ThrowError(Exception inner, String persistedState, String errorPageMessage, Boolean macValidationError) +153
System.Web.UI.ViewStateException.ThrowMacValidationError(Exception inner, String persistedState) +14
System.Web.UI.ObjectStateFormatter.Deserialize(String inputString) +237
System.Web.UI.ObjectStateFormatter.System.Web.UI.IStateFormatter.Deserialize(String serializedState) +4
System.Web.UI.Util.DeserializeWithAssert(IStateFormatter formatter, String serializedState) +37
System.Web.UI.HiddenFieldPageStatePersister.Load() +207
System.Web.UI.Page.LoadPageStateFromPersistenceMedium() +199
System.Web.UI.Page.LoadAllState() +43
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +6785
System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +242
System.Web.UI.Page.ProcessRequest() +80
System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context) +21
System.Web.UI.Page.ProcessRequest(HttpContext context) +49
ASP.web_articolo_aspx.ProcessRequest(HttpContext context) +37
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +181
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75
Here is my code:
<?php
include('simple_html_dom.php');
//method for logging
function login($url,$data){
$headers = array(
'Host' => 'site',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language' => 'en-US;q=0.5,en;q=0.3',
'Accept-Encoding' => 'gzip, deflate',
'Referer' => 'http://somesite.com',
'Connection' => 'keep-alive',
'Content-Type' => 'application/x-www-form-urlencoded'
);
$login = curl_init();
curl_setopt($login, CURLOPT_COOKIEJAR, dirname(__FILE__) . "/cookie.txt");
curl_setopt($login, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/cookie.txt");
curl_setopt($login, CURLOPT_TIMEOUT, 4000);
curl_setopt($login, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($login, CURLOPT_URL, $url);
curl_setopt($login, CURLOPT_HEADER, 1);
curl_setopt($login, CURLOPT_HTTPHEADER, $headers);
curl_setopt($login, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0');
curl_setopt($login, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($login, CURLOPT_POST, 1);
curl_setopt($login, CURLOPT_POSTFIELDS, $data);
//$verbose = curl_setopt($login, CURLOPT_VERBOSE, true);
$ris = curl_exec ($login);
curl_close($login);
unset($login);
return $ris;
}
//method for posting data
function post_data($site,$data){
$datapost = curl_init();
curl_setopt($datapost, CURLOPT_URL, $site);
curl_setopt($datapost, CURLOPT_TIMEOUT, 4000);
curl_setopt($datapost, CURLOPT_HEADER, 1);
//curl_setopt($datapost, CURLOPT_HTTPHEADER, $headers);
curl_setopt($datapost, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:40.0) Gecko/20100101 Firefox/40.0');
curl_setopt($datapost, CURLOPT_POST, 1);
curl_setopt($datapost, CURLOPT_POSTFIELDS, $data);
curl_setopt($datapost, CURLOPT_COOKIEFILE, dirname(__FILE__) . "/cookie.txt");
$result = curl_exec ($datapost);
curl_close ($datapost);
return $result;
}
function getParamLogin($url,$pageType) {
//return the html page
$html = file_get_html($url);
$eventtarget = '';
$eventargument = '';
if(sizeof($html->find('[id=__EVENTTARGET]')) > 0)
$eventtarget = $html->find('[id=__EVENTTARGET]')[0]->value;
if(sizeof($html->find('[id=__EVENTARGUMENT]')) > 0)
$eventargument = $html->find('[id=__EVENTARGUMENT]')[0]->value;
//post params
$params = array('ctl00_ScriptManager1_HiddenField' => $html->find('[id=ctl00_ScriptManager1_HiddenField]')[0]->value,
'__EVENTTARGET' => $eventtarget,
'__EVENTARGUMENT' => $eventargument,
'__VIEWSTATE' => $html->find('[id=__VIEWSTATE]')[0]->value,
'__VIEWSTATEGENERATOR' => $html->find('[id=__VIEWSTATEGENERATOR]')[0]->value,
'__EVENTVALIDATION' => $html->find('[id=__EVENTVALIDATION]')[0]->value,
'ctl00$search' => '',
'ctl00$newsletter' => ''
);
switch ($pageType) {
case 'firstpage':
$login = array('ctl00$pagina$tlogin_area' => 'user',
'ctl00$pagina$tpassword_area' => 'passwd',
'ctl00$pagina$tinvia' => 'ACCEDI',);
$params = array_merge($params,$login);
break;
case 'secondpage':
$cart = array('__SCROLLPOSITIONX' => '0',
'__SCROLLPOSITIONY' => '0',
'ctl00$pagina$taglie' => '6M',
'ctl00$pagina$tag' => 'Aggiungi al carrello');
$params = array_merge($params,$cart);
break;
}
print_r($params);
return $params;
}
?>
<?php
login('http://www.loginpage.com', getParamLogin('http://www.loginpage.com','firstpage'));
post_data('http://www.anotherpage.com',getParamLogin('http://www.anotherpage.com','secondpage'));
?>
I wonder if there is also a cookie in handle the cookie and then in the viewstate... Someone can help me? Thank you!
I have a small problem with php curl post.
I am trying to post some turkish characters to a forum but aren't posted how it should be.
This is how i save the text:
fwrite($fpp,"\xEF\xBB\xBF");
fwrite($fpp, $row['template']);
fclose($fpp);
and posting:
$this->curl = curl_init();
curl_setopt ( $this->curl, CURLOPT_URL, $this->vb_url . 'newthread.php?' . $url_vars );
curl_setopt ( $this->curl, CURLOPT_POST, true );
curl_setopt ( $this->curl, CURLOPT_POSTFIELDS, $post_fields );
curl_setopt ( $this->curl, CURLOPT_RETURNTRANSFER, true );
curl_setopt ( $this->curl, CURLOPT_CONNECTTIMEOUT,20);
curl_setopt ( $this->curl, CURLOPT_TIMEOUT,10);
curl_setopt ( $this->curl, CURLOPT_HEADER, true );
curl_setopt ( $this->curl, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt ( $this->curl, CURLOPT_COOKIE, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_COOKIEJAR, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_COOKIEFILE, $this->cookie_name );
curl_setopt ( $this->curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1');
$result = curl_exec ( $this->curl );
this is how it should be:
`Bölüm resimleri, dizi indirme ve altyazı linkine aşağıdan ulaşabilirsiniz.`
this is how it is posted:
`Bölüm resimleri, dizi indirme ve altyazı linkine aşağıdan ulaşabilirsiniz.`
Thanks
From http://php.net/manual/es/function.curl-setopt.php
Try adding:
curl_setopt($this->curl,CURLOPT_HTTPHEADER,array (
"Content-Type: application/x-www-form-urlencoded; charset=utf-8"
));
application/x-www-form-urlencoded suggested by #spencercw
Fixed with
$message = #iconv("UTF-8","Windows-1252//IGNORE",$message);
Trying to do some local testing on a virtual server, the problem is cURL is returning a http_code => 0
I think it's to do with my virtual host naming.
Virtual Host Name: dev.project
the cURL request is adding http://
if I ping: dev.project from the command line, I get a hit.
If I try it with http://dev.project I get unknown host.
Is there a curl_setopt option just to use the hostname? I'm no sure if I can use the IP as there are several projects on the server, or would Apache handle this?
Here is what I have tried:
$request_url = 'dev.project';
$request_args = 'parm=1234';
$user_agent = 'Mozilla/5.0 (X11; U; Linux i686; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.151 Safari/534.16';
$ch = curl_init();
// set curl options (GET)
curl_setopt($ch, CURLOPT_URL, $request_url.'?'.$request_args);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//curl_setopt($ch, CURLOPT_FAILONERROR, TRUE);
//curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
//curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
//curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // CHANGE THIS TO TRUE
// Set curl options (POST)
//curl_setopt($ch, CURLOPT_URL, $request_url);
//curl_setopt($ch, CURLOPT_POST, TRUE);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $request_args);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
//curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
//curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($ch);
echo "<pre>".print_r($response,true)."</pre><br />\n"; // nothing is returned
print_r(curl_getinfo($ch));
curl_close($ch);
Response from curl_getinfo() : (NOTE: the http:// is pre-pended in the url)
Array
(
[url] => http://dev.project?parm=1234
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0
[namelookup_time] => 0
[connect_time] => 0
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => 0
[upload_content_length] => 0
[starttransfer_time] => 0
[redirect_time] => 0
)
If anyone has this issue, here is the fix:
// This is your Virtual Hosts name
$request_host = 'dev.project';
// This is the IP
$request_url = '192.168.0.1';
$headers = array("Host: ".$request_host);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $request_url.'?'.$request_args);
curl_setopt($ch, CURLOPT_HEADER, FALSE);