#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    77
    Rep Power
    2

    Return content to previous page


    Hi all,

    I have this problem I hope you can help me out with.

    In an user registration script I check if the email is already in use. If it is not in use, continue with registration. else return to previous page(index.php)

    Currently I use header(); to redirect back to the index page. But I would like to append additional html to the index page on return. Something like <h1>The email is already in use</h1>
    How would I go about doing that?

    BTW. I checked this post as PHP5 but it displays as PHP4 ???
  2. #2
  3. No Profile Picture
    I haz teh codez!
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2003
    Posts
    2,540
    Rep Power
    2337
    Set a message in the session. On the login page, check for the presence of that message in the session and if it's there, print it on the page.
    I ♥ ManiacDan & requinix

    This is a sig, and not necessarily a comment on the OP:
    Please don't be a help vampire!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2004
    Posts
    11
    Rep Power
    0
    The simple way would be to pass a value in the URL like this...

    PHP Code:
    header("location: /index.php?msg=duplicate%20email%20detected"); 
    On the index.php page, look for that variable and if it is there display it. You may want to test it first but if you are just displaying it using htmlentities you should be fine regardless of what is in the message.

    PHP Code:
    if(isset($_REQUEST["msg"])) echo "<h1 style='red'>".htmlentities($_REQUEST["msg"])."</h1>"
    You can get more complex but that is the basic idea.
  6. #4
  7. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,749
    Rep Power
    9397
    Originally Posted by odp
    BTW. I checked this post as PHP5 but it displays as PHP4 ???
    You sure it said PHP4? It said nothing... I just changed it to PHP5 to see what would happen and that seems fine.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    77
    Rep Power
    2
    Originally Posted by schworak
    The simple way would be to pass a value in the URL like this...

    PHP Code:
    header("location: /index.php?msg=duplicate%20email%20detected"); 
    On the index.php page, look for that variable and if it is there display it. You may want to test it first but if you are just displaying it using htmlentities you should be fine regardless of what is in the message.

    PHP Code:
    if(isset($_REQUEST["msg"])) echo "<h1 style='red'>".htmlentities($_REQUEST["msg"])."</h1>"
    You can get more complex but that is the basic idea.
    Thanks guys that worked perfectly

IMN logo majestic logo threadwatch logo seochat tools logo