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
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
Do this
As for your session issue, have a file called (for example)
loginCheck.phpInside that file, you should have something like the following
In your login page, after you’ve logged the user in successfully, set the variable in the session
And when the user logs out
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.