Jump to content

Archived

This topic is now archived and is closed to further replies.

bcmiller

*SOLVED* Strange PHP server problem

Recommended Posts

Hi all,
I have made a couple of sites using this code;
[code]
                    <?
                    $ext = ".php";
                    $pg = "".$pg."".$ext."";
                    if (file_exists($pg))
                    {
                    include($pg);
                    } else {
                    include("error.php");
                    }
                    ?>
[/code]

The $pg is part of the URI (eg; example.php?pg=myblog )
I just changed to a new host, and now the page will only show 'error.php' not 'myblog.php'. I tried to echo $pg, and the result was just ".php".
Is this a server problem, or is it my problem?
TIA

Share this post


Link to post
Share on other sites
try calling for the variable with global variable $_GET[];

[code]
<?
$page=$_GET['pg'];
                    $ext = ".php";
                    $pg = "".$page."".$ext."";
                    if (file_exists($pg))
                    {
                    include($pg);
                    } else {
                    include("error.php");
                    }
                    ?>[/code]

Share this post


Link to post
Share on other sites
Your new host most probably has the register_globals directive switched off which is a good thing. However any scripts worked on your old host will not work with your new host due to regsiter_globals.

If register_globals on you can retrieve any variables form the url, posted data, cookies, session like this:
$varname

Howver with register_globals off you will need to use the superglobal array varibales which are the following:
$_POST, $_GET, $_SESSION, $_SESSION etc.

So for you as you have varibales set in the url you will need to use the $_GET superglobal array like so:
$_GET['pg']

You will only use:
$_GET when you have variables set in the url.
$_POST when you have form data being submitted with the method set as post.
$_COOKIE for cookie data, and
$_SESSION for session data.

register_globals can be a security issue when its switched on as a vister can reguster a variable and as long as your script has the same variable name you use in ascript they can erase any data that variable holds! However superglobals stop this from happing as an variables set in the url, post'd data, cookies, sessions are categories in their own special variables.

Have a look at [a href=\"http://www.php.net/variables.predefined\" target=\"_blank\"]Superglobals[/a] over at php.net and have a look at [a href=\"http://uk.php.net/manual/en/security.globals.php\" target=\"_blank\"]Register Globalsp[/a] too for good for a good explanation of why not to have regsiter_globals on.

Share this post


Link to post
Share on other sites

×

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.