Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7833555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:46:05+00:00 2026-06-02T12:46:05+00:00

I am struggling to set up a redirection after successfully logging in by user.

  • 0

I am struggling to set up a redirection after successfully logging in by user.

The login page should redirect the user to the page where they were refused to access after they have successfully logged in.

For example, if a user clicks on ‘My Account’ before logging in (no session) then they are redirected to login page successfully but once they are logged in, how do I send them back to the “My Account” page?

Methods I tried include $_SESSION['HTTP_REFERER].

Any help would be much appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T12:46:07+00:00Added an answer on June 2, 2026 at 12:46 pm

    Using $_SERVER['HTTP_REFERER'] is dangerous, since the referrer would be the same login page if the user received an error while trying to login (such as wrong password). You should store the back URL inside a session variable before redirecting the user to the login page, then, after they successfully log in, redirect them to the stored back URL.

    For example, say you need to protect page.php, you could have something like this at the beginning of the file:

    if (empty($_SESSION['user'])) {
        $_SESSION['backURL'] = $_SERVER['REQUEST_URI'];
        header('Location: login.php');
        exit;
    }
    

    Then, after the user successfully logs in, you could populate the $_SESSION['user'] variable then redirect to the URL you stored before sending him to the login page (or to the root of the site if it so happens that you don’t have any back URL stored for whatever reason):

    $backURL = empty($_SESSION['backURL']) ? '/' : $_SESSION['backURL'];
    unset($_SESSION['backURL']);
    header('Location: ' . $backURL);
    exit;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm struggling with ways how to input user preferences for given set. I have
I have been struggling to make a set of reports that gives the sum
Struggling with this one. I have set up a basic email/enquiry form for a
A Visual Studio user struggling w/ Eclipse... I imported a set of servlets/JSPs into
I have been struggling to set the value of JHTML Area. But no luck.
Using ASP.NET MVC 3, I have been struggling to set the selected value for
I'm struggling through getting everything set up here, I have my extension installed in
I am really struggling with using the SqlLite in my App; I have set
I am struggling to set an background image for an QPushButton. No Success till
I am struggling with getting Inno Setup to set the check box to true

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.