Jump to content

working fine on local pc but not on server


bhavin12300

Recommended Posts

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.

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.