Jump to content

Archived

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

ramzess

Switch is not working because of register_globals off

Recommended Posts

Hi guys!

I just found out that my code for changing contents of a table cell is not working on some servers.
Later I found out why - it is because 'register_globals'  in php.ini is Off. On ones I tried this simple script
it was On.

This is my simple code. Sure now way to make it even more simple. But What can I do about it?
How can I define this variable $cng? If I define it a value script stops working. :(
I can't believe - it should be so common to use this one, please, is there really no way out?


[code]<?php
switch ($cng) {

case "1";
require ('content/page1.php');
break;

case "2";
require ('content/page2.php');
break;

default;
require ('content/page0.php');
}
?>[/code]

Of course, links for calling in those pages is like:

<a href="?cng=1">Page 1</a> and <a href="?cng=2">Page 2</a>


Is there a solution? Thank you.

Share this post


Link to post
Share on other sites
Get the value of the variable from the querystring
[code]
$cng = $_GET['cng'];

switch ($cng) {
[/code]

When coding, always assume the register_globals setting is OFF

Share this post


Link to post
Share on other sites
Thank you Barand. Thank you.

Oh yes, from now on I will work with register_globals Off to escape such situations
when you suddenly find something is not working somewhere.

Thank you.

Share this post


Link to post
Share on other sites
This should help

http://www.php.net/manual/en/language.variables.external.php

Share this post


Link to post
Share on other sites

×

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.