working fine on local pc but not on server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

sunny12300
Forum Newbie
Posts: 14
Joined: Thu Jan 01, 2009 11:51 pm

working fine on local pc but not on server

Post by sunny12300 »

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.
here is my code

Code: Select all

<?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

waiting for your reply.
esmarts
Forum Newbie
Posts: 14
Joined: Fri Aug 08, 2008 10:05 pm

Re: working fine on local pc but not on server

Post by esmarts »

Have you tried running

phpinfo()
on your server
and comparing your settings with your localhost settings?
sunny12300
Forum Newbie
Posts: 14
Joined: Thu Jan 01, 2009 11:51 pm

Re: working fine on local pc but not on server

Post by sunny12300 »

esmarts wrote:Have you tried running

phpinfo()
on your server
and comparing your settings with your localhost settings?
thanks for your reply.
but when i try to use phpinfo(); on server, it display nothing.
any other way?
server does support curl feature.
but dont know why it is not working on server.
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: working fine on local pc but not on server

Post by novice4eva »

It would be better if you enable the error reporting and see what's causing the problem.
sunny12300
Forum Newbie
Posts: 14
Joined: Thu Jan 01, 2009 11:51 pm

Re: working fine on local pc but not on server

Post by sunny12300 »

novice4eva wrote:It would be better if you enable the error reporting and see what's causing the problem.
how to do that sir.
i used this line to see error from curl but getting no info from it.

Code: Select all

echo  $response['Error'];
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: working fine on local pc but not on server

Post by novice4eva »

Stick these two lines at the top of your code.

Code: Select all

 
    ini_set('display_errors', 1);
    ini_set('error_reporting', E_ALL);
 
User avatar
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

Re: working fine on local pc but not on server

Post by The_Anomaly »

sunny12300 wrote:
esmarts wrote:Have you tried running

phpinfo()
on your server
and comparing your settings with your localhost settings?
thanks for your reply.
but when i try to use phpinfo(); on server, it display nothing.
any other way?
server does support curl feature.
but dont know why it is not working on server.
Well, shoot, I'd think that that would be a serious problem. Unless your host somehow disabled phpinfo() (maybe they can do that, I don't know), are you processing PHP at all? Your issue is almost certainly that you have a different configuration on your server than your local host. The best way to find this problem is to compare phpinfo()s like esmarts said. I'd highly recommend trying to figure out why phpinfo() isn't working, and get it to work, so you can find your configuration error.
sunny12300
Forum Newbie
Posts: 14
Joined: Thu Jan 01, 2009 11:51 pm

Re: working fine on local pc but not on server

Post by sunny12300 »

hi
thanks for your reply.
as my previous server dont allow me to run phpinfo on it.
i moved to other and its allowing me to run phpinfo.
should should i compare on page on server with the page on local computer??
waiting
User avatar
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

Re: working fine on local pc but not on server

Post by The_Anomaly »

Is any PHP working at all?

Try this:

Code: Select all

 
<?php
 
echo "Peanuts.";
 
?>
Do you see "Peanuts."?
sunny12300
Forum Newbie
Posts: 14
Joined: Thu Jan 01, 2009 11:51 pm

Re: working fine on local pc but not on server

Post by sunny12300 »

ya
all my script working except this one.
here is script with phpinfo on it.
Last edited by sunny12300 on Fri Jan 02, 2009 5:35 am, edited 1 time in total.
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: working fine on local pc but not on server

Post by novice4eva »

Did you try enabling the error with the code i have posted earlier in the page which is giving you trouble??
User avatar
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

Re: working fine on local pc but not on server

Post by The_Anomaly »

First off, what'd you do to get phpinfo() to work, and why wasn't it working before? More for curiosity's sake, I'm wondering if it was somehow disabled on your server.

Second, you really don't want to make your phpinfo() public. It's like giving the world the keys to cracking your server wide open. All information you might want to crack it is in there.
sunny12300
Forum Newbie
Posts: 14
Joined: Thu Jan 01, 2009 11:51 pm

Re: working fine on local pc but not on server

Post by sunny12300 »

novice4eva wrote:Did you try enabling the error with the code i have posted earlier in the page which is giving you trouble??
yes sir i did but no error message.
sunny12300
Forum Newbie
Posts: 14
Joined: Thu Jan 01, 2009 11:51 pm

Re: working fine on local pc but not on server

Post by sunny12300 »

The_Anomaly wrote:First off, what'd you do to get phpinfo() to work, and why wasn't it working before? More for curiosity's sake, I'm wondering if it was somehow disabled on your server.

Second, you really don't want to make your phpinfo() public. It's like giving the world the keys to cracking your server wide open. All information you might want to crack it is in there.
i changed the server.and phpinfo working on this server .it still does not work on old server.
can you let me know why my script not working on server?any configuration needed to be done?
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: working fine on local pc but not on server

Post by novice4eva »

maybe it has to do with the COOKIE_FILE, but even if it were... then error should have popped out!! Did you check if the file is there or if it is writable, there is this verification done in one of the examples at http://www.php.net/curl

EDIT : there is also an example for checking errors in curl here http://www.php.net/manual/en/function.curl-errno.php
Post Reply