bhavin12300 Posted December 31, 2008 Share Posted December 31, 2008 hi i have one script which uses curl to login to one site.it is working fine on my local computer but not login properly when i upload my script to server. my pc is winodws xp. server does support curl feature. i am maintaining cookie too. please let me know what should i do to make it run on server. waiting for your reply. Quote Link to comment Share on other sites More sharing options...
bluesoul Posted December 31, 2008 Share Posted December 31, 2008 Uh. Any error messages or anything? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted December 31, 2008 Share Posted December 31, 2008 Code? Ken Quote Link to comment Share on other sites More sharing options...
flyhoney Posted December 31, 2008 Share Posted December 31, 2008 If you're server is *nix I think you will need to recompile PHP with cURL. If it is windows you should be able to just add the extension. If you can't do that, you may be able to use file or file_get_contents or something like that instead of the cURL functions. Quote Link to comment Share on other sites More sharing options...
bhavin12300 Posted January 1, 2009 Author Share Posted January 1, 2009 Uh. Any error messages or anything? no sir not any error message. Quote Link to comment Share on other sites More sharing options...
bhavin12300 Posted January 1, 2009 Author Share Posted January 1, 2009 Code? Ken here is code <?php $action ='login form url'; $ref=''; $method='POST'; $response = http($target=$action, $ref, $method, $data, EXCL_HEAD); echo $response['FILE']; function http($target, $ref, $method, $data_array, $incl_head) { # Initialize PHP/CURL handle $ch = curl_init(); # Prcess data, if presented if(is_array($data_array)) { # Convert data array into a query string (ie animal=dog&sport=baseball) foreach ($data_array as $key => $value) { if(strlen(trim($value))>0) $temp_string[] = $key . "=" . urlencode($value); else $temp_string[] = $key; } $query_string = join('&', $temp_string); } #i am directly sending post data here.not using data array.hope you got it $query_string ='username=xxxx&password=yyyy&acc-password-txt=Password&x=47&y=8'; if($method == HEAD) { curl_setopt($ch, CURLOPT_HEADER, TRUE); curl_setopt($ch, CURLOPT_NOBODY, TRUE); } else { # GET method configuration if($method == GET) { if(isset($query_string)) $target = $target . "?" . $query_string; curl_setopt ($ch, CURLOPT_HTTPGET, TRUE); curl_setopt ($ch, CURLOPT_POST, FALSE); } if($method == POST) { if(isset($query_string)) curl_setopt ($ch, CURLOPT_POSTFIELDS, $query_string); curl_setopt ($ch, CURLOPT_POST, TRUE); curl_setopt ($ch, CURLOPT_HTTPGET, FALSE); } curl_setopt($ch, CURLOPT_HEADER, $incl_head); curl_setopt($ch, CURLOPT_NOBODY, FALSE); } curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE_FILE); curl_setopt($ch, CURLOPT_COOKIEFILE, COOKIE_FILE); curl_setopt($ch, CURLOPT_TIMEOUT, CURL_TIMEOUT); curl_setopt($ch, CURLOPT_USERAGENT, WEBBOT_NAME); curl_setopt($ch, CURLOPT_URL, $target); curl_setopt($ch, CURLOPT_REFERER, $ref); curl_setopt($ch, CURLOPT_VERBOSE, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE); curl_setopt($ch, CURLOPT_MAXREDIRS, 4); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); $return_array['FILE'] = curl_exec($ch); $return_array['STATUS'] = curl_getinfo($ch); $return_array['ERROR'] = curl_error($ch); curl_close($ch); return $return_array; } ?> my cookie file is in c:/cookie.txt Quote Link to comment Share on other sites More sharing options...
bhavin12300 Posted January 1, 2009 Author Share Posted January 1, 2009 If you're server is *nix I think you will need to recompile PHP with cURL. If it is windows you should be able to just add the extension. If you can't do that, you may be able to use file or file_get_contents or something like that instead of the cURL functions. hi sir,i think my server is *nix.can you tell me what you mean by recompile with curl?? i want to post login detail to form and maintain my session in does file or file_get_contents support it? Quote Link to comment Share on other sites More sharing options...
bhavin12300 Posted January 2, 2009 Author Share Posted January 2, 2009 any one please guide me. waiting for your reply. Quote Link to comment Share on other sites More sharing options...
bhavin12300 Posted January 4, 2009 Author Share Posted January 4, 2009 i came to know that there is something wrong with request made by server. what i mean is when i run script on linux server, it is making request using "GET" to make for login thought i am making true for post and false for get request in curl option.while on windows it is using "POST" . SO I THINK I SHOULD CHANGE SOME PARAMETER OR DO SOMETHING SO SCRIPT ON SERVER WILL MAKE REQUEST IN "POST" DO YOU KNOW HOW? HERE IS MY HEADER FOR LINUX 1. * About to connect() to www28.discuss.com.hk port 80 (#0) 2. * Trying 124.XXX.150.30... * connected 3. * Connected to http://www.discuss.com. (124.244.150.30) port 80 (#0) 4. > GET /logging.php?action=login& HTTP/1.1 5. User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.1.6) Gecko/20070725 Firefox/2.0.0.6 6. Host: www28.discuss.com.hk 7. Accept: */* 8. Referer: http://www.discuss.com/logging.php?action=login 9. please atleast any one help me out. Quote Link to comment Share on other sites More sharing options...
bhavin12300 Posted January 5, 2009 Author Share Posted January 5, 2009 please any one? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.