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

  • Home
  • SEARCH
  • 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 6960193
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:22:14+00:00 2026-05-27T15:22:14+00:00

I usually restrict user access by redirecting users if they don’t have a valid

  • 0

I usually restrict user access by redirecting users if they don’t have a valid session.

For example:

<?php
  session_start();
  if (!isset($_SESSION["userInfo"])) {
    header("Location: index.php");
  }
?>

but I’m starting a new project using ajax for all my page loads.

How should I force a page refresh of my webapp if the session is no longer valid?

ShouldIi precede all my ajax request with a dedication authentication request, and if that fails refresh the page via javascript?

Or, should I just include authentication data in each of my json responses and then authenticate before any further handling of the ajax requests?

Is there a better way to do this?

  • 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-27T15:22:14+00:00Added an answer on May 27, 2026 at 3:22 pm

    Ideally, you engineer your client-side code well enough so you have a way to handle various errors from the server-side.

    When your client-side code makes an ajax call, it should look at the status of the response. If the user has no session, the server should reply with 401 (Unauthorized) response, which means “that’s a valid URL, but you need to be authenticated”.

    Whenever your client-side code gets a 401, it should do whatever is necessary to get the user logged in. This could be redirecting them to a login screen, or doing some kind of modal authentication DHTML-popup.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Usually when defining a DAO, you would have a setter for the datasource on
Usually I come across situations where I have to swallow an exception thrown by
Usually, before setting up a UILabel, we have to initialize CGRect like below CGRect
Usually, when a trigger runs, we check what kind of a profile the user
Usually I would have a table field called ID on auto increment. That way
Usually, making a a block, you just have to hover on the <li> to
Usually, when we have to link an interface element to a field of a
One problem that I come across regularly and yet don't have a solution to
Usually, when sending a http status header from PHP, one would send the HTTP
Usually when you design a website you don't want to take apart a complete

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.