Jump to content

Recommended Posts

Hello,

I'd like to open a new php document as the result of a condition check (if/elseif statement). If certain criteria apply during the execution of a search, then a specific file should be loaded. Vars don't need to be passed, no database action needed.
I tried an echo of the following code, which obviously didn't work  :P ::)
(just showing the basic html here!)
[code]<HTML>
<HEAD>
<NOSCRIPT>
<META http-equiv="Refresh" content="0; URL=http://www.mysite.com/noresult.php">
</NOSCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>[/code]

:-\
...as in, go to another page, or including the file? be more specific. here are some examples:

[code]
$blah = 1;
if ($blah == 1) {
  // example 1: redirect to new page
  header('Location: newpage.php'); exit;

  // example 2: include the script
  include('somepage.php');
} else {
  // condition was false. spit out error or access denied or stick your tongue out at them
}
[/code]

I've read the sticky, other posts concerning this issue, etc.
I'm passed the "header already sent" warnings and all that... but the redirect still doesn't work.
The php code is above my <html>, checked if the condition statement is true etc? Any advise?

[code]
$total = 0
if ($total = 0){
header("Location: newsearch.php");
}[/code]
[code]
$total = 0;
if ($total == 0){
header("Location: newsearch.php"); exit;
}
[/code]

- you forgot a ; to terminate your first expression.
- you used = instead of == in your condition.  = is the assignment operator, == is the equality operator.
- you need to add exit; after a header call when you redirect, to keep any further script from being executed.
- make sure that newsearch.php is named right, in the right directory (as shown, it should be in the same directory as this script
- still not working after all that? check to make sure this code isn't wrapped inside some other condition that is evaluating false.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.