Jump to content

Recommended Posts

I'm no PHP expert - I've cobbled my knowledge together from articles, books, etc. My website has worked fine for 4 years but I recently changed hosts and now some of my php scripts aren't working properly. I don't know what my site used to be hosted on, but my test setup on my own PC is XP, Apache 1.3.XX, PHP 4, MySQL 4, etc. My new hosting environment for the live site is Linux and I suspect that might be the problem.

I'm not sure if I can be brief and give enough detail, but a few examples are:

I use horizontal tabs for some sections of my site. I wrote some code myself to look inside the current directory, determine if a certain php file is present, and if it is then display a tab. The type of tab depends on whether the php page is current or not. If the file doesn't exist in the current directory, then no tab is displayed.

This is all achieved by declaring variables using $HTTP_GET_VARS, and then using IF... ELSE, file_exists, case... switch... break, substr_count, PHP_SELF and a function.

A second example is a quick and simple browser detect, looking for specific browser agents. The site then displays things differently depending on what it detected as viewing the site. This code also excluded large images from being displayed in the AvantGo PDA offline browser application. Unfortunately, this code now thinks that the main browser is AvantGo and so won't display the large images!

This code uses stristr and HTTP_USER_AGENT as well as the usual $HTTP_GET_VARS for variables and again it used to work perfectly...

I'm assuming that I need to do some tweaking somewhere (php.ini?) on the server, but have no idea where to start! it's just annoying that code that worked fine before is no longer working as it should. The versions of Apache, PHP, MySQL etc. are close to the ones I have on my test setup, so I'm fairly sure it isn't a PHP4 vs PHP5 kind of issue.

Help?
Thanks for responding so quickly! :-)

Oops. I meant to have included all of the symptoms in that post!

Basically, I don't get any errors - the code is simply not behaving properly. The tabs example simply shows all the tabs regardless - it's as if the checking is no longer working - i.e. it thinks they should all be present all the time. It's as if the variable used or the file_exists part of the code isn't working anymore.

The fact that I am relying on things like PHP_SELF and HTTP_USER_AGENT makes me wonder if there's something not turned on or not configured correctly that makes these behave differently. The actual logic behind the code works fine and has done for 4 years, so it can only be something to do with the way PHP (or maybe Apache?) is configured on the server.

I'm hoping that these general symptoms ring a bell or two with someone here?

[!--quoteo(post=380529:date=Jun 6 2006, 09:56 AM:name=samshel)--][div class=\'quotetop\']QUOTE(samshel @ Jun 6 2006, 09:56 AM) [snapback]380529[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I think we would ned some details of you old environment...If it was windows and you transferred on Linux, the paths used can cause problems.

In any case..what are the errors you are getting ?
[/quote]
[!--quoteo(post=380536:date=Jun 6 2006, 10:33 AM:name=samshel)--][div class=\'quotetop\']QUOTE(samshel @ Jun 6 2006, 10:33 AM) [snapback]380536[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Check for register_globals in your php.ini, try switching it on / off and check
[/quote]

Unfortunately, that hasn't fixed it but I can understand why you suggested it! ;-)

However, I have come across another very weird thing about the PHP code for showing (or not showing) larger images when you click on a thumbnail. This code contains three 'cases' - one for AvantGo, one for the Sony PSP and one that covers every other browser. The AvantGo case just happened to be stated first (and was based upon a variable being set to =1 if my browser detect code knew it was AvantGo) and it was this that was kicking in every time regardless of the browser.

When I put the case for everything else (i.e. normal browsers) in first (with a variable that should =0) then that case is used instead! It's as if the code simply uses whichever case appears first, regardless of the variable's value or the logic that tells it which case it should be using! This I simply don't understand - the logic is fine and on the old host this worked perfectly. I don't get why either the PHP configuration or the fact that my new host is Linux based should have any effect on whether this PHP code works or not.

As a result, I have no idea what I can do to get this code working correctly. The very same code works perfectly on my own test setup (XP) - so is it the OS, the PHP configuration or maybe the Apache configuration that might be affecting this in some way?

The relevant section from the code is shown below:

<?php
$running = $HTTP_GET_VARS["running"];
$altag = $HTTP_GET_VARS["altag"];
$fi = $HTTP_GET_VARS["fi"];
$shot = $HTTP_GET_VARS["shot"];
include ("./inc/browse.inc");
switch ($pda) {

case $pda=1:
echo ("<br />
<p align='center'>
Sorry, large images not available on AvantGo. Select 'back' on your device to return to previous page.</p>
<br />
<br />

</body>
</html>");

break;

case $pda=2:
echo ("
<p align='center'>
<b>".$altag."</b></p>
<p align='center'>
<img src='images/".$fi."/".$shot."' alt='".$altag."' /></p>
<p align='center'>
<a href=\"javascript:window.close();\">Close</a></p>

</body>
</html>");

break;

case $pda=0:
echo ("
<p align='center'>
<b>".$altag."</b></p>
<p align='center'>
<img src='images/".$fi."/".$shot."' alt='".$altag."' /></p>
<p align='center'>
<b>< << <a href=\"javascript:window.close();\">Close</a> >> ></b></p>
</p>

</body>
</html>");

break;

}
?>

As I said before, whichever case is stated first ends up being the one it uses - regardless of whether it should use it (based upon the browser) or not!

The browse.inc code is:

<?php
if (stristr($_SERVER['HTTP_USER_AGENT'],"avantgo")) {
$pda = "1";
}
elseif (stristr($_SERVER['HTTP_USER_AGENT'],"psp")) {
$pda = "2";
}
else {
$pda = "0";
}
?>

Any other suggestions would be much appreciated, as I have no idea what to try next.
first of all, avoid using $HTTP_GET_VARS, use $_GET instead for compatibility reasons.

second of all, that seems to be incorrect use of switch/case.
here's a valid example:
[code]
switch($var)
{
    case 1:
            echo 'Var is 1';
        break;

    case 2:
    case 4:
            echo 'Var is an even number below 5';
        break;

    case 3:
            echo 'Var is 3';
        break;

    case 5:
            echo 'Var is 5';
        break;

    default:
            echo "Var is $var";
        break;
}
[/code]

always have a "default" case in the even that an unexpected value is input.


i haven't read through all your posts. post more code here if you want help because one thing can be done in many ways in PHP so it's better that we see some code before we can figure out how to help you :)
As mentioned above you should use should use the new superglobal arrays $_POST, $_GET, $_SESSION etc rather than using the old depriciated global variables $HTTP_*_VARS

Also your new host ruinning linux might be running PHP5 with the register_long_arrays directive turned off. register_long_arrays are the old global variables $HTTP_*_VARS i mention above.
Hi,

Changing the way I write the cases (i.e. to case 1:) has fixed the tab issue! Now, the only thing that makes me curious is why! i.e. is it the different version of PHP or is it down to the PHP configuration? Anyway, many thaks for that - I have also changed to $_GET as well.

I have a few other issues, but at least I can cross this off my 'to fix' list now!

Many Thanks!

[!--quoteo(post=380923:date=Jun 7 2006, 09:51 AM:name=Bane)--][div class=\'quotetop\']QUOTE(Bane @ Jun 7 2006, 09:51 AM) [snapback]380923[/snapback][/div][div class=\'quotemain\'][!--quotec--]
first of all, avoid using $HTTP_GET_VARS, use $_GET instead for compatibility reasons.

second of all, that seems to be incorrect use of switch/case.
here's a valid example:
[code]
switch($var)
{
    case 1:
            echo 'Var is 1';
        break;

    case 2:
    case 4:
            echo 'Var is an even number below 5';
        break;

    case 3:
            echo 'Var is 3';
        break;

    case 5:
            echo 'Var is 5';
        break;

    default:
            echo "Var is $var";
        break;
}
[/code]

always have a "default" case in the even that an unexpected value is input.
i haven't read through all your posts. post more code here if you want help because one thing can be done in many ways in PHP so it's better that we see some code before we can figure out how to help you :)
[/quote]
[!--quoteo(post=381051:date=Jun 7 2006, 05:18 PM:name=Richard_Hewison)--][div class=\'quotetop\']QUOTE(Richard_Hewison @ Jun 7 2006, 05:18 PM) [snapback]381051[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi,

Changing the way I write the cases (i.e. to case 1:) has fixed the tab issue! Now, the only thing that makes me curious is why! i.e. is it the different version of PHP or is it down to the PHP configuration? Anyway, many thaks for that - I have also changed to $_GET as well.

I have a few other issues, but at least I can cross this off my 'to fix' list now!

Many Thanks!
[/quote]

In fact, these two changes have resolved all of my outstanding issues, including some very weird MySQL ones which also used cases and variables.

Many thanks for pointing out these issues. I doubt I'd have ever sussed them out otherwise!
[!--quoteo(post=381051:date=Jun 7 2006, 10:18 PM:name=Richard_Hewison)--][div class=\'quotetop\']QUOTE(Richard_Hewison @ Jun 7 2006, 10:18 PM) [snapback]381051[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi,

Changing the way I write the cases (i.e. to case 1:) has fixed the tab issue! Now, the only thing that makes me curious is why! i.e. is it the different version of PHP or is it down to the PHP configuration? Anyway, many thaks for that - I have also changed to $_GET as well.

I have a few other issues, but at least I can cross this off my 'to fix' list now!

Many Thanks!
[/quote]


glad you sorted it out :)

you should really take wildteen88's advice seriously. he makes a valid point there regarding future compatibility issues.
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.