Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 15 of 15
  1. #1
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to go to another web page on conditional results

    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
    Fishermen are born honest, but they soon outgrow it.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    You can use either the HTML meta tag to redirect the user, or Javascript's window.location method:
    Code:
    <script type="text/javascript">
    window.location = 'http://newurl.com';
    </script>
    But it is considered preferable to use the header() function.

  • #3
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Fishermen are born honest, but they soon outgrow it.

  • #4
    Senior Coder whizard's Avatar
    Join Date
    Jan 2005
    Location
    Philadelphia, PA, USA
    Posts
    1,662
    Thanks
    14
    Thanked 76 Times in 76 Posts
    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
    PHP Tip: If you want to use short tags (<? or <?=$var) then make sure short_open_tag is set to "1". It really helps.

    Don't forget to save everyone time and mark your thread as Resolved :)

    "Also note that it is your responsibility to die() if necessary."

    DON'T USE THE MYSQL_ EXTENSION

  • #5
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Fishermen are born honest, but they soon outgrow it.

  • #6
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    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.
    John

  • #7
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by pops View Post
    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
    PHP Code:
    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

  • #8
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by pops View Post
    It appears that the header() function is only good for redirect.
    If you don't need to redirect the user, you can include() the page you want to display instead.

  • #9
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oesxyl View Post
    is not a php problem, your design is the problem

    suppose you use $_POST
    PHP Code:
    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,
    Fishermen are born honest, but they soon outgrow it.

  • #10
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by pops View Post
    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

  • #11
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oesxyl View Post
    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:

    PHP Code:
    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
    Fishermen are born honest, but they soon outgrow it.

  • #12
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by pops View Post
    The code I am concerned with here is:

    PHP Code:
    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:

    PHP Code:
    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
    Last edited by oesxyl; 03-15-2008 at 01:36 AM.

  • #13
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oesxyl View Post
    if both "option 1" and "option 2" are passed, the second if is useless.
    you can use something like:

    PHP Code:
    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
    Fishermen are born honest, but they soon outgrow it.

  • #14
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by pops View Post
    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
    PHP Code:
    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.

    PHP Code:
    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
    Last edited by oesxyl; 03-15-2008 at 01:55 AM.

  • #15
    New to the CF scene
    Join Date
    Sep 2003
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by oesxyl View Post
    PHP Code:
    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.

    PHP Code:
    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
    Fishermen are born honest, but they soon outgrow it.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •