PHP Script behaves differently on different servers

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

Post Reply
php_ghost
Forum Commoner
Posts: 55
Joined: Thu Jan 11, 2007 3:29 am

PHP Script behaves differently on different servers

Post by php_ghost »

Guys,
I have this captcha script and it behaves differently on my test server and production server.

the code looks like this:

Code: Select all

 
<?php
session_start();
if ($_SESSION['captchacode']=='' && !isset($_POST['captchasubmit'])) {
    echo "Condition 1";
}elseif($_SESSION['captchacode'] == $_POST['captchasubmit']){
    echo "Condition 2";
}elseif($_SESSION['captchacode'] != $_POST['captchasubmit']){
    echo "Condition 3";
}
?>
 
In the test server, it works perfectly. Howerver, in the production server, it doesn't display anything on the browser. Have you guys encountered this? What could be the common cause for this? The two servers have different configurations etc. but this is the first time I have encountered a script that works this way.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: PHP Script behaves differently on different servers

Post by jaoudestudios »

Put an else on the end and see if it is falling through your script.
i.e.

Code: Select all

 
...
else {
   echo "error";
{
 
php_ghost
Forum Commoner
Posts: 55
Joined: Thu Jan 11, 2007 3:29 am

Re: PHP Script behaves differently on different servers

Post by php_ghost »

tried it. it still displays nothing.

also i've got another part of the script which contains a loop.
the code looks like this:

Code: Select all

    
for ($i = 0; $i < $flakes; $i++) {
    $x1 = mt_rand(0, 200);
    $y1 = mt_rand(0, 50);
    $x2 = $x1 + mt_rand(-2, 2);
    $y2 = $y1 + mt_rand(-2, 2);
    imageline($im, $x1, $y1, $x2, $y2, $fore);
}
In Production, when I place an echo statement inside this loop, it displays the text just once unlike in my test server, it loops correctly.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PHP Script behaves differently on different servers

Post by pickle »

set the error reporting level to E_ALL at the top of your script.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
php_ghost
Forum Commoner
Posts: 55
Joined: Thu Jan 11, 2007 3:29 am

Re: PHP Script behaves differently on different servers

Post by php_ghost »

pickle wrote:set the error reporting level to E_ALL at the top of your script.
Yeah tried it already. The script when in production, still doesn't display anything.
php_ghost
Forum Commoner
Posts: 55
Joined: Thu Jan 11, 2007 3:29 am

Re: PHP Script behaves differently on different servers

Post by php_ghost »

php_ghost wrote:tried it. it still displays nothing.

also i've got another part of the script which contains a loop.
the code looks like this:

Code: Select all

    
for ($i = 0; $i < $flakes; $i++) {
    $x1 = mt_rand(0, 200);
    $y1 = mt_rand(0, 50);
    $x2 = $x1 + mt_rand(-2, 2);
    $y2 = $y1 + mt_rand(-2, 2);
    imageline($im, $x1, $y1, $x2, $y2, $fore);
}
In Production, when I place an echo statement inside this loop, it displays the text just once unlike in my test server, it loops correctly.
Alright it looks like this part of the script is what screws everything up. When I removed this entire For loop block, everything worked fine on production. But with this on, test is ok, production is jacked up. So what could be the problem with this block then? Any ideas?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PHP Script behaves differently on different servers

Post by pickle »

The errors might also be going to a file rather than the screen. Do this:

Code: Select all

ini_set('display_errors',true);
or something similar - not 100% sure what the syntax is.

You can make a phpinfo() file to check what the ini settings are as well.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: PHP Script behaves differently on different servers

Post by jaoudestudios »

Check your server errors log
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: PHP Script behaves differently on different servers

Post by jaoudestudios »

Oh what about different versions of php?
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: PHP Script behaves differently on different servers

Post by Mark Baker »

jaoudestudios wrote:Oh what about different versions of php?
You'd be more likely to see an error (e.g. undefined function) with different versions of PHP.
Different php.ini might cause discrepancies though.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: PHP Script behaves differently on different servers

Post by jaoudestudios »

production server wont show errors, just blank screen. Errors logs would record it though
Post Reply