Jump to content

register globals


brown2005

Recommended Posts

if(!isset($page))$page="home";

switch($page)
{

case "home":$file="files/home.php";
break;

case "test":$file="files/test.php";
break;

}

 

i have this code for changing pages, and i asked in a previous post about why it would work in one site and not in another, and i was told to switch on register globals, which i have seen a few times, as should be off, but how would i get around the above code, if i have them off

Link to comment
Share on other sites

Never turn on register globals

 

To make your code work, you need to use the correct superglobal array, in this case $_GET

<?php
$page = (isset($_GET['page']))?$_GET['page']:'home';

switch($page) {
   case "home":
      $file="files/home.php";
      break;
   case "test":
      $file="files/test.php";
      break;
}
?>

 

Ken

Link to comment
Share on other sites

i was told to switch on register globals

 

I hope that was not on this forum!

 

no, i mean i wasnt told to turn them on.. i was told

 

Probably the fact the one has register globals off (recommended) and one has them on (frowned upon).

 

but i turned them on. which i now know was a no no.

Link to comment
Share on other sites

but i turned them on. which i now know was a no no.

 

Turn them off and fix your code to work properly. It is a security risk having them on and they will soon be left out (I think PHP6 you can no longer turn them on/off). Read up on them at http://www.php.net/register_globals

 

Basically instead of accessing the variable with just $varname it would be $_GET['varname']. It is a very basic and easy change/fix to any code, just some people are to lazy to take the hour or so it may take to fix their variable declarations.

 

EDIT:

Security risk, potentially anyone can gain authenticated access to a site if the site is not coded properly by declaring variables. For example $_SESSION['loggedin'] is what a bunch of people use. If they just access this by $loggedin I just pass page.php?loggedin=true  and wham I am authenticated.  (Given that they did not code for this which if register_globals is on the chances are high.)

Link to comment
Share on other sites

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.