Hello all
first of all im sorry about my english writing
my problem is :
1- my first page is index.php
users after login going to input.php
but my problem is here my users can enter the input.php in the url and going to input.php page without login
how can i solve this problem?
i have a lot of thanks for you’r time
You should Disable/remove session code( the user session variable like $_SESSION) which stores logged in user information …
and you user directly login to your input.php URL.
Care to expand on why sessions should not be used?
Welcome to our site, php.programmer021 ! ! ! Do not worry about your English. We will understand you.
Glad you can join us here…
Now, to answer your question. As Astonecipher said, just use the $_SESSION[] array. It is simple and it
works well. Here is how you do it…
In the beginning of each page, place this line:
session_start();
This will start your session. This allows you to communication from page to page and send variables back
and forth between pages.
In your login page, use the above line as the first line. Then, after the user’s username and password
have been validated, you just set a session variable like this:
$_SESSION[“Login”]=“yes”;
You can use any name for the variable and any value you want. This is just an example.
Then, in every page in the rest of the site, such as your input.php file, you add a check for that variable.
At the top of the input.php file, place this code…
session_start();
if ($_SESSION[“Login”]!=“yes”) header(“Location: noaccess.php”);
In this way, if the user is not logged in, it will send them to another page which I called noaccess.php.
That page would display a warning that they are not allowed on the page they tried to visit.
If someone types in one of your pages, it would send them to the noaccess.php page. Or, you could just
have them go to the login page instead. Either way works…
Hope that helps…
First I am Sorry …
I guess wrong your question.
You can try this solution :-
1)first start a session .
using session_start() method…
2)create a session variable to store login user info. like
$_SESSION[‘username’] = $user (value from entered input type in index.php)
3)than check if $user is exists in your records than allow that user to redirect to input.php page like :-
header(‘Location:input.php’);
Glad that you solved it…
But, do not forget #4
On every page in your site, check to see if the user is logged in. If not send them to another page.
If they are logged in, show the current page…