SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 49
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Redirection question

    Hi All,

    Another day, another question!

    I think this should be pretty simple. I have a page which (thanks to alot of help) allows a user to enter their email address and a password and add this into a database. From here I need to redirect the user to a different page to fill in some details, dependant on the button which they clicked on the page previous to the email/password details page.

    e.g. Home page-> click button1 -> enter email/password -> redirect to page1
    Home page -> click button2 -> enter email/password -> redirect to page2

    Unless somebody has a better way of doing this?

    Any advice would be appreciated.

    EDIT: I suppse another way would be for each button to link to a different URL which contained the email/password fields and then redirect based on the URL they came from? Any ideas how to approach this?

  2. #2
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just been looking for more info on this. I assuem I can use the $_SERVER[HTTP_REFERER] parameter to find out the URL the user came from, but how would this work based on a button press from the same URL?

    Maybe I will have to incorporate some more pages?

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    If you use form buttons on the home page, then just give them a name (e.g. "button1" and "button2"). On the email/password page, just redirect according to the button pressed on the home page.

    If you use links on the home page, just add a parameter to the url (e.g. "mail.php?button=1") and on the email/password page, redirect according to the value of $_GET["button"].

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so should it look like this?

    PHP Code:
    if(isset($_GET["button"]=1)
    header("Location:page1.php".SID);
    if(isset(
    $_GET["button"]=2)
    header("Location:page2.php".SID); 
    or is this wrong?

  5. #5
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    PHP Code:
    if ($_GET["button"] == 1
    {
           
    header("Location:page1.php".SID); 
           exit();
    }
    if (
    $_GET["button"] == 2
    {
           
    header("Location:page2.php".SID); 
           exit();


  6. #6
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks I shall see if it works. Sorry, I'm very new to PHP

  7. #7
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry guido, I can't get it to work.

    It just refreshes the page if I enter the correct information.

    Any other ideas?

  8. #8
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    oracle,
    just out of interest, why have you got two buttons to do the same thing then direct to different urls?

    What is the form for? is it a username/ password login page?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  9. #9
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is a finance site. The front page gives instruction on how to apply for a particular loan/mortgage etc... then the user selects which they want by clicking on the required button.

    This then takes them through to the email/password form, which will store their infomration and then pass them onto the form which is relevant to their loan/mortgage etc..

    I thought it would save time if I could have just one login page, rather than 6 different ones. One for each form etc...

    So all I want is for someone to click on 'Mortgage', fill in their email/password details and be directed to the 'Mortgage' application form.

    I hope this makes sense.

  10. #10
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anybody?

  11. #11
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you post the code that calls the above script.... ?

  12. #12
    SitePoint Guru
    Join Date
    Nov 2004
    Location
    Parry Sound, ON
    Posts
    725
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On the home page, if the two buttons are in two separate forms just give two different actions, i.e. action="mail.php?page=1"

    On the mail page dynamically change the action of the form.
    <form name="blah" method="post" action="page<?=$_GET['page'] ?>.php">

  13. #13
    SitePoint Enthusiast JoJoNAloha's Avatar
    Join Date
    Nov 2004
    Location
    Oregon
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, i'm new too...but just an idea... maybe have them input their email and password first and then go to the page with the buttons where they select their loan/mortgage

  14. #14
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here it is:

    PHP Code:
    <?php 

    include("includes/dbconn.inc"); 
    include(
    "includes/funclib.inc"); 

    $message_header ="<span class='style16'><b><BR><BR>We were unable to complete your login due to the following error(s):<b><BR></span>"

    if (
    array_key_exists('actionflag',$_POST)) 
        { 
        
    $actionflag=$_POST['actionflag']; 
        
    $login=$_POST['login']; 
        
    $password=$_POST['password']; 
        
    $password2=$_POST['password2']; 
        } 

    if(isset(
    $actionflag)) 
        { 
        if((!isset(
    $login)) || (!isset($password)) || (!isset($password2))) 
            
    $message .= "<span class='style32'>You must fill in all fields before applying<BR></span> \n"
        if(
    $password!=$password2
            
    $message .= "<span class='style32'>Your passwords did not match<BR></span> \n"
        if(
    strlen($password) > 8
            
    $message .= "<span class='style32'>Your password must be less than 8 characters<BR></span> \n"
        if (!
    preg_match('/^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$/',$login)) 
            
    $message .= "<span class='style32'>Please enter a valid email address</span>" 
        if(
    getRow("user_details","username"$login)) 
            
    $message .= "<span class='style32'>The email address " .$login" has already been used. Please contact us if you wish to make another application<BR></span> \n"
        if(!
    $message
        { 
        
    $id newUser($login$password); 
        
    cleanMemberSession($id$login$password); 
        if (
    $_POST["button"] == "1"
        { 
           
    header("Location: http://localhost/Right-Track/page1.php".SID); 
           exit(); 
        } 
        if (
    $_POST["button"] == "2"
        { 
           
    header("Location: http://localhost/Right-Track/page2.php".SID); 
           exit(); 
        }
        if (
    $_POST["button"] == "3"
        { 
           
    header("Location: http://localhost/Right-Track/page3.php".SID); 
           exit(); 
        }
        if (
    $_POST["button"] == "4"
        { 
           
    header("Location: http://localhost/Right-Track/page4.php".SID); 
           exit(); 
        }
        if (
    $_POST["button"] == "5"
        { 
           
    header("Location: http://localhost/Right-Track/page5.php".SID); 
           exit(); 
        }
        if (
    $_POST["button"] == "6"
        { 
           
    header("Location: http://localhost/Right-Track/page6.php".SID); 
           exit(); 
        } 
        }

    ?> 

    <?php 
    if(isset($message)) 

    print 
    $message_header."<br>"$message.""

    ?>
          <div align="center"></div>
          <form action="<?php print $_SERVER['PHP_SELF']; ?>" method="post">
            <p align="left">
              <input type="hidden" name="actionflag" value="join">
              <input type="hidden" name="<?php print session_name(); ?>" value="<?php print session_id(); ?>">
              <span class="style27 style8 style29">Email Address:</span> <br>
              <input name="login" type="text" value="<?php echo $login?>" size="35" maxlength="80">
              <span class="style27 style8 style29">Password:</span><br>
              <input type="password" name="password" value="" size=15 maxlength="8">
              <br>
              <span class="style31">Confirm Password:</span> <br>
          <input type="password" name="password2" value="" size=15 maxlength="8">
            </p>
            <p align="left">
              <input name="submit" type="submit" value="Apply Now">
            </p>
          </form>
    The buttons, are just links. They aren't form buttons, but thx for the suggestion.

    Hope someone can help get this working.

  15. #15
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    If the buttons on the first page, that pass the client to the email form, ain't form buttons, but simple links with the "button" variable in the url, you can't use $_POST. You have to use $_GET.

  16. #16
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is what I had it set to originally and it didn't work.

    I will change it back and see if it makes a difference

  17. #17
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have changed it back to $_GET['button'] == '1'; but this has still not worked.

    It must just be my if statements as the functions are being used, and the database is being updated but it stil l just refreshes the screen (leaving the email address in the box).

  18. #18
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, some errors! (I set error reporting on)

    Notice: Undefined variable: link in C:\phpWeb\Right-Track\includes\dbconn.inc on line 2

    Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\phpWeb\Right-Track\includes\dbconn.inc:2) in C:\phpWeb\Right-Track\includes\funclib.inc on line 3

    Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\phpWeb\Right-Track\includes\dbconn.inc:2) in C:\phpWeb\Right-Track\includes\funclib.inc on line 3

    Warning: Cannot modify header information - headers already sent by (output started at C:\phpWeb\Right-Track\includes\dbconn.inc:2) in C:\phpWeb\Right-Track\includes\funclib.inc on line 4


    Just so you can see, my 2 include files:

    funclib.inc

    PHP Code:
    <?php
    session_start
    ();
    header('Cache-Control: public'); 

    function 
    cleanMemberSession($id$login$pass)
        {
        
    $_SESSION[id] = $id;
        
    $_SESSION[login] = $login;
        
    $_SESSION[password] = $pass;
        
    $_SESSION[logged_in] = true;
        }
        
    ?>
    dbconn.inc

    PHP Code:
    <?php
    $link
    ;
    connectToDB();
    function 
    connectToDB()
        {
        global 
    $link;
        
    $link mysql_connect("localhost","root","quiksilver");
        if(!
    $link)
            die(
    "Could not connect to MySQL");
        
    mysql_select_db("righttrack"$link);    

        }
        
    function 
    newUser($login$pass)
        {
        global 
    $link;
        
    $result=mysql_query("insert into user_details (username, password)
                            values('
    $login', '$pass')"$link);
        return 
    mysql_insert_id($link);
        }
        
    function 
    getRow($table$fnm$fval
        { 
        global 
    $link
        
    $result=mysql_query("select * from $table where $fnm='$fval'"$link); 
        if(!
    $result
            die(
    "getRow fatal error: " .mysql_error()); 
        return 
    mysql_fetch_array($result); 
    }
    ?>
    Not sure what all this means. I've probably messed up big time, but any advice appreciated.

    Thanks.

  19. #19
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    I could be wrong but it does seem like you are calling $link (in dbconn.inc) before you have defined is as the function. This might explain the first error message.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  20. #20
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK cool, how do I correct this?

  21. #21
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, so I now put in ob_start(); before my includes and the header errors have gone away. The 2 undefined variables link, and login are still there.

    If I add in the correct details and submit again, I get the following errors:

    Code:
    Notice: Undefined variable: link in C:\phpWeb\Right-Track\includes\dbconn.inc on line 2 
    
    Notice: Undefined variable: message in C:\phpWeb\Right-Track\auth.php on line 29 
    
    Notice: Use of undefined constant id - assumed 'id' in C:\phpWeb\Right-Track\includes\funclib.inc on line 7 
    
    Notice: Use of undefined constant login - assumed 'login' in C:\phpWeb\Right-Track\includes\funclib.inc on line 8 
    
    Notice: Use of undefined constant password - assumed 'password' in C:\phpWeb\Right-Track\includes\funclib.inc on line 9 
    
    Notice: Use of undefined constant logged_in - assumed 'logged_in' in C:\phpWeb\Right-Track\includes\funclib.inc on line 10 
    
    Notice: Undefined index: button in C:\phpWeb\Right-Track\auth.php on line 33 
    
    Notice: Undefined index: button in C:\phpWeb\Right-Track\auth.php on line 38 
    
    Notice: Undefined index: button in C:\phpWeb\Right-Track\auth.php on line 43 
    
    Notice: Undefined index: button in C:\phpWeb\Right-Track\auth.php on line 48 
    
    Notice: Undefined index: button in C:\phpWeb\Right-Track\auth.php on line 53 
    
    Notice: Undefined index: button in C:\phpWeb\Right-Track\auth.php on line 58

    This obviously shows that something is wrong with the button varibale.

    I have changed the headers to the JS
    Code:
    echo "<script>self.location='page3.php" . SID . "';</script>";
    as suggested by somebody else, to remove the header errors aswell.

  22. #22
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Would undefined index mean that it is not set? In which case, how can I get it to set? I am going though from the front page and the URL says auth.php?button=2

    I'm really struggling with this now, please help me get it sorted. Thanks.

  23. #23
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do I need anything PHP wise on the front page where I'm passing ?button=1 from? I thought I could just set the link to auth.php?button=1 - Would I have to declare this somewhere?

  24. #24
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    PHP Code:
    function cleanMemberSession($id$login$pass
        { 
        
    $_SESSION[id] = $id
        
    $_SESSION[login] = $login
        
    $_SESSION[password] = $pass
        
    $_SESSION[logged_in] = true
        } 
    should be

    PHP Code:
    function cleanMemberSession($id$login$pass
        { 
        
    $_SESSION["id"] = $id
        
    $_SESSION["login"] = $login
        
    $_SESSION["password"] = $pass
        
    $_SESSION["logged_in"] = true
        } 

  25. #25
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    In your form action, you'll have to send the 'button' value again, otherwise it won't be defined anymore when you click the submit button and validate the form:

    <form action="<?php print $_SERVER['PHP_SELF']; ?>?button=<?php print $_GET['button']; ?>" method="post">


Bookmarks

Posting Permissions

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