SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast rad2004's Avatar
    Join Date
    Aug 2004
    Location
    UK
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    header redirection question

    hello,

    the scenario is:
    user lands on mail.php?type=inbox
    If user is not logged in he is redirected to a login page via:
    header('Location: login.php?url=mail.php?'.urlencode($_SERVER['QUERY_STRING']));

    ... after entering correct username and password he is sent back to the original page via:

    header('Location: http://example.com/'.urldecode($url));

    The above code works.
    My question is whether it's the correct way to do it.

  2. #2
    SitePoint Addict skunkbad's Avatar
    Join Date
    Apr 2008
    Location
    Temecula, CA
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, it kind of depends where $url is coming from. You don't show that in your code, but I'm assuming it is the query string. I do something different for my site, but I don't think it's wrong what you are doing.

    On my site a page checks for a user being logged in, and shows either

    a) content if the user is logged in
    b) the login form

    If the user successfully logs in, which is a post to self, then the content is shown.

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2009
    Posts
    65
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No, I think there is nothing wrong you are doing.

  4. #4
    SitePoint Enthusiast rad2004's Avatar
    Join Date
    Aug 2004
    Location
    UK
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks, my main concern I suppose was with the correct use of urlencode and urldecode

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The second question mark should probably be urlencoded.

    Also, consider doing some validation on the url.


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
  •