Jump to content

[SOLVED] register global off, Notice: Undefined variable: action in.... problem


bbmak

Recommended Posts

Hi,

I used to built script with register global on in php 4, but after they released php 5, register global is off

 

 

 

the problem is I used " if ($action ==  " in my script.

The script will show error " Notice: Undefined variable: action in...."  in php 5 with default register global off

 

Although, I can build the script will an emulation of register global on with the following code

<?

// Emulate register_globals on

if (!ini_get('register_globals')) {

$superglobals = array($_SERVER, $_ENV,

$_FILES, $_COOKIE, $_POST, $_GET);

if (isset($_SESSION)) {

array_unshift($superglobals, $_SESSION);

}

foreach ($superglobals as $superglobal) {

extract($superglobal, EXTR_SKIP);

}

}

?>

 

 

 

I want to know how do I overcome this problem? I want to use 'if ($action ==' but i want the register global stays off.

 

 

I do not always want to use register global emulation script and I do not want to make the php5 to register global on.

 

 

 

Yes, you can do that tapos, but this is old style and outdated way of doing things. Also, why create and use up extra memory with more variables when they're all already populated in predefined variables for you.

 

toplay can you show me how to replace my code here with $_request ???

 

if ($action == 'show')

{

...

}

what is the colon for : ? in this  $_REQUEST['action'] : ???

toplay can you show me how to replace my code here with $_request ???

 

if ($action == 'show')

{

...

}

what is the colon for : ? in this  $_REQUEST['action'] : ???

 

 

$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';

if ($action == 'show')

{

...

}

 

To know more about the ? : syntax, look for ternary operator info on this manual page:

http://us.php.net/manual/en/language.operators.comparison.php

 

Archived

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

×
×
  • 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.