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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:02:33+00:00 2026-05-28T18:02:33+00:00

Well I have a question, See for example I have some web pages on

  • 0

Well I have a question, See for example I have some web pages on my website like profile.php , photos.php and some more

Okay when user logs in he will be redirected to his profile.php but i got a question suppose if user enters this url without logging in like http://www.somewebsite.com/profile.php and hits enter. The browser will direct him to the profile.php page and the profile.php throws out errors like undefined variables and all because we load the profile.php page according to user input on the homepage

So I want to redirect user to homepage whenever he opens any webpage on mywebsite and send him a message that please login to continue.

So then I thought and I got a solution. I thought to use session_start() and give some session value on the index page and in all other pages i would check isset() so if session is set profile.php page executes else it will redirect him to homepage

Something like this

all otherwebpages will have this on the top

    <?php
    session_start();
   if(!(isset($_SESSION['unique'])))
    {
    header("Location: www.someexample.com");
            exit;

    }

but let me know is this the way to do? or is it a bad way of doing it? are there any better solutions in doing so. any help is greatly appreciated.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-28T18:02:34+00:00Added an answer on May 28, 2026 at 6:02 pm

    First, fix the errors that you get in your profile page if you access it directly.

    This is most likely because you’re accessing indexes that don’t exist in your POST or GET variable.

    Instead of doing this (assuming you are POSTing

    $username = $_POST['username'];
    

    Do this

    $username = isset($_POST['username']) ? $_POST['username'] : '';//won't throw error
    

    As for your session issue, have a file called (for example) loginCheck.php

    Inside that file, you should have something like the following

       //session_start(); //session_start should be in an application wide global file
    
       //this code should only be in pages where you want to have login enabled
       if(!isset($_SESSION['user_logged_in']) || !$_SESSION['user_logged_in']) {
          header("Location: URL_TO_LOGIN_PAGE");
          exit;
       }
    

    In your login page, after you’ve logged the user in successfully, set the variable in the session

    //login success
    $_SESSION['user_logged_in'] = true;
    //store other stuff in the session like user settings and data
    

    And when the user logs out

    //login success
    $_SESSION['user_logged_in'] = false;
    

    Note that it’s better to have two global common files. One that initializes your application and that is included in all your scripts (that starts the session as well) and another page that is included when you want to close off parts of the system that does the session check.

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

Sidebar

Related Questions

The question seems pretty well formulated I have a virtual machine which implements only
Well, I have a simple question, at least I hope its simple. I was
I have two tables (well, two relevant for this question) : Bets (holds the
As well as my question Removing MKMapView Annotations causes leaks. I have discovered that
Well, the question is kinda simple. I have a object defined as: public class
Ok another WPF question, well I guess this is just general .NET. I have
well i have this messages table with sample values like these: msg_id recipient_id read
Well I have a videos website and a few of its tables are: tags
I'd like some feedback on my current architecture. I have a Person resource that
EDIT The bare-bones version of this question is, if I have some object o

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.