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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Oct 2009
    Posts
    438
    Thanks
    9
    Thanked 7 Times in 7 Posts

    Login script to go back to page you were just on

    All,
    If I have a login link on the top of every page. How can I go to my login script and have it redirect back to the page that I was just on?

    Thanks.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    You may send an extra variable in that link to indicate the page from which the link is clicked and write a switch -case block to compare this value in the login page to decide the target page.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Oct 2009
    Posts
    438
    Thanks
    9
    Thanked 7 Times in 7 Posts
    Do you have an example on how to do this? Appreciate it.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    That depends on your system. I use a variable $page in all my pages(obtained from parsing $_SERVER['REQUEST_URI']) and my login link would look like
    PHP Code:
    <a href="login.php?page=<?php echo $page;?>">Login</a>
    or
    PHP Code:
    <a href="/login/<?php echo $page;?>/">Login</a>
    (in case of a friendly url setup )

    My login.php page reads the request from $_GET['page'], and stores this value in session or a hidden variable.

    On a successful login, a switch block like
    PHP Code:
    if(!empty($_SESSION['page'])){
    switch(
    $_SESSION['page'])
    case 
    'home'$target='index.php?page=home';
                       
    #or home.php or whatever
                       
    break;
    case 
    'about'$target='index.php?page=about';
                       
    #or about.php or whatever
                       
    break;
    ...
    }
    unset(
    $_SESSION['page']);
    }
    if(!isset(
    $target))
     
    $target='profile.php'
    header("Location:"$target); #you may need to add the complete path here 
    Hope this helps.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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