Jump to content

Archived

This topic is now archived and is closed to further replies.

stefands

Loading new file via php as result condition check

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]

:-\

Share this post


Link to post
Share on other sites
...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]

Share this post


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

The redirect doesn't work.
How can I break out of an if/elseif statement and go to an other page?

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
Share on other sites

×

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.