stefands Posted October 28, 2006 Share Posted October 28, 2006 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] :-\ Quote Link to comment https://forums.phpfreaks.com/topic/25407-loading-new-file-via-php-as-result-condition-check/ Share on other sites More sharing options...
.josh Posted October 28, 2006 Share Posted October 28, 2006 ...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] Quote Link to comment https://forums.phpfreaks.com/topic/25407-loading-new-file-via-php-as-result-condition-check/#findComment-115899 Share on other sites More sharing options...
stefands Posted October 28, 2006 Author Share Posted October 28, 2006 [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? Quote Link to comment https://forums.phpfreaks.com/topic/25407-loading-new-file-via-php-as-result-condition-check/#findComment-116004 Share on other sites More sharing options...
stefands Posted November 1, 2006 Author Share Posted November 1, 2006 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 = 0if ($total = 0){header("Location: newsearch.php");}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/25407-loading-new-file-via-php-as-result-condition-check/#findComment-117837 Share on other sites More sharing options...
.josh Posted November 1, 2006 Share Posted November 1, 2006 [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. Quote Link to comment https://forums.phpfreaks.com/topic/25407-loading-new-file-via-php-as-result-condition-check/#findComment-118005 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.