Forum Moderators: coopster

Message Too Old, No Replies

IF Statements and Empty Variables

         

branmh

9:35 pm on Jan 21, 2004 (gmt 0)

10+ Year Member



I need to know how to do an IF Statement with a Empty Variable and how it to redirect to another page.

I have tried this code but all it does to contiunes to reload.


if (empty($section)) {
header("Location: index.php?section=index");
exit;
}

So if you goto /index.php it would reload to /index.php?section=index

coopster

9:40 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



If register_globals [php.net] is ON, you may need to check the $_GET [php.net] superglobal array instead:

if (empty($_GET['section'])) {

Birdman

9:41 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use the isset() function for that. Note the exclamation, which says 'if the var is not set'. Without the exclamation, the if statement would execute when the var 'isset'.

if (!isset($section))
{
header("Location: index.php?section=index");
exit;
}

coopster

10:45 pm on Jan 21, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Good point, Birdman. branmh, there is a difference between empty [php.net] and isset [php.net]. You may want to make sure you are using the correct function. msg #2 will still apply here, no matter which function you choose to use.