bcmiller Posted April 11, 2006 Share Posted April 11, 2006 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 Quote Link to comment https://forums.phpfreaks.com/topic/7091-solved-strange-php-server-problem/ Share on other sites More sharing options...
shortj75 Posted April 11, 2006 Share Posted April 11, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/7091-solved-strange-php-server-problem/#findComment-25756 Share on other sites More sharing options...
wildteen88 Posted April 11, 2006 Share Posted April 11, 2006 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:$varnameHowver 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. Quote Link to comment https://forums.phpfreaks.com/topic/7091-solved-strange-php-server-problem/#findComment-25775 Share on other sites More sharing options...
bcmiller Posted April 11, 2006 Author Share Posted April 11, 2006 THANK YOU! Quote Link to comment https://forums.phpfreaks.com/topic/7091-solved-strange-php-server-problem/#findComment-25835 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.