View Full Version : I don't even know why this won't work
Mob1us
11-14-2006, 07:23 PM
Okay, so I noticed a problem with a page I was putting on a bravenet.com website of mine, and I simplified the file again and again until it came down to this:
<?php
if(!$step)
{
echo "Step is null";
}
elseif($step == edit)
{
echo "Step is set to \"edit\"";
}
?>
and for some reason that won't work on my bravenet.com site: http://www.cbts.halo2leagues.com/3.php but it will work on this free hosting site http://weberc2.coconia.net/3.php
The problem is that, regardless of the variable's value in the query string, it ALWAYS reads the variable as null. If anyone can offer some insight into this, that'd be great.
Acey99
11-14-2006, 11:53 PM
cause $step == edit
not $step == "edit".
remember to use your string values :)
Also, you probably mean $_GET['step']. $step is not defined in the above code unless register_globals is set.
Mob1us
11-15-2006, 04:18 PM
It's designed to set the "step" variable's value in the query string, and as for the quotation marks around the variable in elseif ($step == "edit") it works regardless of whether they're in there or not on one server, but on the other it doesn't work at all regardless of either.
To see what I mean, try typing http://weberc2.coconia.net/3.php?step=edit to see what the functional file would look like; however, the same portion of the same file on the other host reads the variable in the query string as null as shown here: http://www.cbts.halo2leagues.com/3.php?step=edit
I know what it's designed to do, but it doesn't.
as for the quotation marks around the variable in elseif ($step == "edit") it works regardless of whether they're in there or not on one server, but on the other it doesn't work at all regardless of either.It really shouldn't work without them. The other server likely has register_globals disabled, so $step is undefined.
<?php
if(empty($_GET['step']))
echo 'Step is empty';
else if($_GET['step'] === 'edit')
echo 'Step is set to "edit"';
?>
Acey99
11-15-2006, 05:29 PM
ok so if register_globals is off (which it should be)
use this at the top of the code to reload vars at their names (like register_globals = on does)
<?php
/*
Reloads Cookies, Post vars, & Get vars as their own variables.
eg:
$_COOKIE['name'] : $name=value;
$_POST['somename'] : $somename = somenamevalue;
$_GET['somename'] : $somename = somenamevalue;
so if you have a form name of "Firstname" you'll have:
$_POST['Firstname'] OR $_GET['Firstname'] AND $Firstname
also a fix for register_globals = off
*/
foreach ($_POST as $k=>$v) $$k=$v; # Reload Posts
foreach ($_GET as $k=>$v) $$k=$v; # Reload Gets
foreach ($_COOKIE as $k=>$v) $$k=$v; # Reload Cookies
?>
But that totally defeats the point of not using register_globals in the first place. One might as well just re-enable it.
Rather than using $_GET, $_POST, and $_COOKIE, you can use $_REQUEST, which contains values from all three.
Mob1us
11-18-2006, 11:01 PM
I see.. Could you please show me how to write code for this file using the $_request? I've already checked PHP.net and I still don't understand. Thank you very much.
<?php
if(empty($_REQUEST['step']))
echo 'Step is empty';
else if($_REQUEST['step'] === 'edit')
echo 'Step is set to "edit"';
?>
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.