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.

 

 

 

Link to comment
Share on other sites

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'] : ???

Link to comment
Share on other sites

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

 

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.