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 400015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T16:54:10+00:00 2026-05-12T16:54:10+00:00

I am currently using PHP/MySQL, and I’d like to know the best way make

  • 0

I am currently using PHP/MySQL, and I’d like to know the best way make an unauthenticated user login, and then have them automatically redirected to the page they logged in.

For example:

1) User tries to open up secure page.
2) They’re re-directed and prompted to login.
3) After they login successfully, they’re taken back to the URL they were trying to access.

Currently, on my “secure” pages, I have the following PHP code set up: (Not even sure if this is the proper way to do ‘secure’ it):

<?php
session_start();

 if ($_SESSION['first'] == "" && $_SESSION['usrID'] == "") {

    print" <script>
   window.location=\"../login/index.php\"
   </script> ";

    }

   ?>

Any suggestions on how to provide this feature (and possibly make my ‘secure’ code better), I’d greatly appreciate it.

Thanks!

  • 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-05-12T16:54:11+00:00Added an answer on May 12, 2026 at 4:54 pm

    You could store the requesting URL in a session var.

    $_SESSION['destination'] = $_SERVER['REQUEST_URI'];
    

    Then, once logging in, you could do something like this:

    if (isset($_SESSION['destination'])) {
    
        header('Location: ' . $_SESSION['destination']);
        exit;
    }
    

    Also, this isn’t such a good idea

      print" <script>
       window.location=\"../login/index.php\"
       </script> ";
    

    Using JavaScript to redirect has problems. For one, nothing will happen with JavaScript disabled. Try sending location headers

    header('Location: ../login/index.php');
    exit; // Call exit to make sure the rest of your code never executes
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to make a simple user login/registration system using PHP and mysql.
I'm currently designing an application using PHP and MySQL, built on the Kohana framework.
I am using PHP and Mysql for developing an application. we have two copies
I'm currently working on a quote retrieval system for my employer's website using mysql/php/html.
currently i'm developing a website in a class in my university. i'm using PHP
Using PHP, I am building an application that is MySQL database resource heavy, but
I am using php to build a change classifieds page right now. I use
I am currently using JQuery Ajax to retrieve and display some data as follows.
Hi I am saving mostly english and german characters into a mysql database which
I need a search engine for a website I am building. I decided to

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.