Jump to content


Photo

*SOLVED* Strange PHP server problem


  • Please log in to reply
3 replies to this topic

#1 bcmiller

bcmiller
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 11 April 2006 - 06:34 AM

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

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

#2 shortj75

shortj75
  • Members
  • PipPipPip
  • Advanced Member
  • 118 posts
  • LocationPort Huron,mi

Posted 11 April 2006 - 07:36 AM

try calling for the variable with global variable $_GET[];

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

The Short One

hopfully this helps if it doesn't sorry
i won't write the code for you!!! you don't learn that way

#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 11 April 2006 - 08:55 AM

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.

#4 bcmiller

bcmiller
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 11 April 2006 - 01:08 PM

THANK YOU!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users