...

View Full Version : How to go to another web page on conditional results



pops
03-14-2008, 09:50 PM
I need to go to another page as the result of an if() statement.

For example: if(true){go to next_page.php;)

All responses I have seen to similar queries are to redirect using header(location:..).
I cannot use header(location:...) in this requirement.

Thanks in advance for any assistance.

Pops

Inigoesdr
03-14-2008, 10:10 PM
You can use either the HTML meta tag (http://en.wikipedia.org/wiki/Meta_refresh) to redirect the user, or Javascript's window.location method:

<script type="text/javascript">
window.location = 'http://newurl.com';
</script>
But it is considered preferable to use the header() function.

pops
03-14-2008, 10:19 PM
Thank you for your response.
I have attempted the header() tag in every way I can think of and it gives me an error.
This conditional statement is after a form submission and based on the response from form I may need to send user to another page.
I was hoping to avoid the javascript solution but that seems to be the only way our for the moment.

Thank you for your time.

Pops

whizard
03-14-2008, 10:35 PM
The header function can only be used before output is sent to the browser (ie before any print or echo statements, for example)

HTH
Dan

pops
03-14-2008, 11:15 PM
It appears that the header() function is only good for redirect.
I am amazed there is no other function to call another page from the code.
Oh well, there are so many advantages and benefits to php that I won't gnash my teeth over it.

Thanks a bunch,

Pops

PappaJohn
03-14-2008, 11:40 PM
I need to go to another page
Sounds like you're looking to redirect the request, but ...

I am amazed there is no other function to call another page from the code.
It may be helpful to describe in more detail what you're trying to do. It's likely there's a way to accomplish it.

oesxyl
03-14-2008, 11:47 PM
It appears that the header() function is only good for redirect.
I am amazed there is no other function to call another page from the code.
Oh well, there are so many advantages and benefits to php that I won't gnash my teeth over it.

Thanks a bunch,

Pops

is not a php problem, your design is the problem

suppose you use $_POST


if(isset($_POST)){
if(test the POST variable here){
// do stuff here, include also redirection if you need
}else{
// redirect to this page, or if the form is properly designed to this page
}
}else{
// this is the first call: show the form
}


do same thing if you use GET, don't use REQUEST is a mess.

best regards

Inigoesdr
03-15-2008, 12:15 AM
It appears that the header() function is only good for redirect.
If you don't need to redirect the user, you can include() (http://php.net/include) the page you want to display instead.

pops
03-15-2008, 12:22 AM
is not a php problem, your design is the problem

suppose you use $_POST


if(isset($_POST)){
if(test the POST variable here){
// do stuff here, include also redirection if you need
}else{
// redirect to this page, or if the form is properly designed to this page
}
}else{
// this is the first call: show the form
}


do same thing if you use GET, don't use REQUEST is a mess.

best regards

This is exactly my situation. My problem is the //redirect to another page

Maybe I just don't understand all that I have read on header()??

Pops,

oesxyl
03-15-2008, 12:29 AM
This is exactly my situation. My problem is the //redirect to another page

Maybe I just don't understand all that I have read on header()??

Pops,
I doubt, header function is too simple, I guess is a problem with passing argument from one page to another, evaluating condition, or else.
Instead of guessing, post the code to see what's wrong, so we could help.

best regards

pops
03-15-2008, 01:12 AM
I doubt, header function is too simple, I guess is a problem with passing argument from one page to another, evaluating condition, or else.
Instead of guessing, post the code to see what's wrong, so we could help.

best regards
The code I am concerned with here is:



if($_POST['option 1']{
go to option1.php;
}
if($_POST['option 2'](
go to option2.php;
}


This is the decision making code and its actions.
Any and all suggestions are welcome.

Pops

oesxyl
03-15-2008, 01:34 AM
The code I am concerned with here is:



if($_POST['option 1']{
go to option1.php;
}
if($_POST['option 2'](
go to option2.php;
}


This is the decision making code and its actions.
Any and all suggestions are welcome.

Pops

if both "option 1" and "option 2" are passed, the second if is useless.
you can use something like:



if(isset($_POST['option 1']) && isset($_POST['option 2'])){
// do something
}elseif(isset($_POST['option 1'])){
// go to option1.php;
}elseif(isset($_POST['option 2']))(
// go to option2.php;
}


It's hard to understand what's wrong with 5 lines of pseudocode but I hope this help you.

best regards

pops
03-15-2008, 01:44 AM
if both "option 1" and "option 2" are passed, the second if is useless.
you can use something like:



if(isset($_POST['option 1']) && isset($_POST['option 2'])){
// do something
}elseif(isset($_POST['option 1'])){
// go to option1.php;
}elseif(isset($_POST['option 2']))(
// go to option2.php;
}


It's hard to understand what's wrong with 5 lines of pseudocode but I hope this help you.

best regards
Thank you.
The logic I understand, it is how to "go to" option1.php or option2.php.
I am at a loss on that.
How do I go to those pages is my quandry.

Thanks for your patience,

Pops

oesxyl
03-15-2008, 01:53 AM
Thank you.
The logic I understand, it is how to "go to" option1.php or option2.php.
I am at a loss on that.
How do I go to those pages is my quandry.

Thanks for your patience,

Pops



if(isset($_POST['option 1']) && isset($_POST['option 2'])){
header("Location: home.php");
}elseif(isset($_POST['option 1'])){
header("Location: option1.php");
}elseif(isset($_POST['option 2']))(
header("Location: option2.php");
}
header("Location: anywhere.php");


this? or I missunderstand the problem?

option1.php and option2.php in some condition could be included, as
Inigoesdr allready said, instead of redirect to them.



if(isset($_POST['option 1']) && isset($_POST['option 2'])){
header("Location: home.php");
}elseif(isset($_POST['option 1'])){
include("option1.php");
}elseif(isset($_POST['option 2']))(
include("option2.php");
}
header("Location: anywhere.php");


best regards

pops
03-15-2008, 03:03 AM
if(isset($_POST['option 1']) && isset($_POST['option 2'])){
header("Location: home.php");
}elseif(isset($_POST['option 1'])){
header("Location: option1.php");
}elseif(isset($_POST['option 2']))(
header("Location: option2.php");
}
header("Location: anywhere.php");


this? or I missunderstand the problem?

option1.php and option2.php in some condition could be included, as
Inigoesdr allready said, instead of redirect to them.



if(isset($_POST['option 1']) && isset($_POST['option 2'])){
header("Location: home.php");
}elseif(isset($_POST['option 1'])){
include("option1.php");
}elseif(isset($_POST['option 2']))(
include("option2.php");
}
header("Location: anywhere.php");


best regards
Thanks a bunch!

Works exactly as I envisioned. Don't know what I was doing wrong before.

Thank all of you for your assistance and patience.

Pops



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum