By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 1,944 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

My php source code do not work

P: n/a
Hi at all
this code it'ld stop and exit if the user do not entered $dbf but it do not
work
Why?

if (!isset($_GET['dbf']) || (isset($_GET['dbf']) && trim($_GET['dbf']) ==
''))
{header('Location: http://www.pablo.es/index.php');
exit();}

May 29 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Pablo wrote:
Hi at all
this code it'ld stop and exit if the user do not entered $dbf but it do
not work
Why?

if (!isset($_GET['dbf']) || (isset($_GET['dbf']) && trim($_GET['dbf']) ==
''))
{header('Location: http://www.pablo.es/index.php');
exit();}
Hi,

Look at the logic:
if
(!isset($_GET['dbf']) || (isset($_GET['dbf']) && trim($_GET['dbf'])== ''))

My guess is you ment:
1) Demand that $_GET['dbf'] is set.
2) And if set, it must contain something (not empty string)

The above mixes the || and && is a strange way.

So try this:
if ( (isset($_GET['dbf']) && (trim($_GET['dbf']) != '')){
// OK
} else {
// Not OK
// header and exit.
}

You do not need the second isset-test this way.
When PHP evaluates the first part (isset($_GET['dbf']) to false and sees the
AND-logic operator && it doesn't even try to evaluate that, because the
if-statement can never evaluate to true.

Regards,
Erwin Moller

May 29 '07 #2

P: n/a
also this make error

if (!isset($_GET['dbf']))
{header("Location:http://www.pablo.es");}

why?
May 29 '07 #3

P: n/a
Pablo wrote:
also this make error

if (!isset($_GET['dbf']))
{header("Location:http://www.pablo.es");}

why?
Hi,

I don't know why it makes an error.
Most probably because your script makes an error somewhere futher down the
script, because you forgot the exit-command after the header.

Try this:
if (!isset($_GET['dbf'])){
header("Location:http://www.pablo.es");
exit;
}

Remember that PHP can set as many headers as you want, and the script runs
on and on and on.
You must stop it yourself by using exit.

Also, try using brackets {} like I did. It makes the code a lot more
readable. :-)
Good luck.

Regards,
Erwin Moller
May 29 '07 #4

P: n/a
Pablo wrote:
also this make error

if (!isset($_GET['dbf']))
{header("Location:http://www.pablo.es");}

why?

What error do you get? If you get a message about headers already being
sent, it means you've output something before the call to header(). You
can't output ANYTHING - not even a blank line - before this call.

Also, to stop execution here, you need to follow it with

exit();

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
May 29 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.