Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/7091-solved-strange-php-server-problem/
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]
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.
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.