Home > Archive > PHP Programming > May 2007 > My php source code do not work
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
My php source code do not work
|
|
|
| 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();}
| |
| Erwin Moller 2007-05-29, 7:00 pm |
| 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
| |
|
|
| Erwin Moller 2007-05-29, 7:00 pm |
| 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
| |
| Jerry Stuckle 2007-05-29, 7:00 pm |
| 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.
jstucklex@attglobal.net
==================
|
|
|
|
|