Results 1 to 7 of 7

Thread: Ok you scripting brainiacs..here's one for you

  1. #1
    Join Date
    May 2007
    Location
    Planet Earth
    Posts
    1,389

    Default Ok you scripting brainiacs..here's one for you

    How do we redirect a user to the last page visited after they log in like it does for the upload page?

    I know how to redirect to a certain page after login, but what about the last page there were visiting? Let's say they are trying to access a member only page...they get the login thing, but then are redirected to either their profile or whatever page is set in the login.php:

    $redirect_url = $config['baseurl'] . '/' . $user_info['user_name'];

    Now they have to hunt for the page they originally intended to view, which is a pain in the butt. It would be nice if they were redirected back to what they were originally doing, just like with the upload page.
    If it's not fun, stop doing it!

  2. #2

    Default

    login.php

    Code:
    $come_from = $_SERVER['HTTP_REFERER'];
    
    if ($come_from == "site.com/login.php"){
    
    $redirect_url = $config['baseurl'] . '/' . $user_info['user_name'];
    
    }else{
    
    $redirect_url = javascript:history.go(-2);
    
     redirect($redirect_url)
    
    }
    $_SERVER['HTTP_REFERER'] isnt the best tracker to use for internal pages but the if else will prevent any bugs
    Last edited by carefree2; 05-15-2009 at 03:01 AM.

  3. #3
    Join Date
    May 2007
    Location
    Planet Earth
    Posts
    1,389

    Default

    Oh hey thanks, can't wait to give it a whirl!!
    If it's not fun, stop doing it!

  4. #4
    Join Date
    May 2007
    Location
    Planet Earth
    Posts
    1,389

    Default

    No matter where I insert that code, I get this:

    Parse error: syntax error, unexpected ':' in /home/j

    ...which is the line about the history..but this gives me a good place to start learning...google, here I come.
    If it's not fun, stop doing it!

  5. #5

    Default

    Its missing a semicolon in the script, use this:


    Code:
    $come_from = $_SERVER['HTTP_REFERER'];
    
    if ($come_from == "site.com/login.php"){
    
    $redirect_url = $config['baseurl'] . '/' . $user_info['user_name'];
    
    }else{
    
    $redirect_url = "javascript:history.go(-2)";
    
     redirect($redirect_url);
    
    }
    Last edited by carefree2; 05-15-2009 at 11:05 PM.

  6. #6
    Join Date
    May 2007
    Location
    Planet Earth
    Posts
    1,389

    Default

    grrrr why is this stuff never simple.

    It tries to return me to df2videos.com/login

    which is a blank page.

    I'll get a hold of a guy I know who is like way into PHP and stuff, I'll see if he come up with something. Thanks.
    Last edited by grynmoors; 05-16-2009 at 06:11 AM.
    If it's not fun, stop doing it!

  7. #7

    Default

    Just make your login a content "box" that gets included/required on any page that you need a login on. It displays the login form if you are not logged in, it submits to the current page since it is just included/required on any page so there is no need to redirect all over the place, and it displays a logout link when you are logged in.

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
  •