Follow users on my website

I know this can be a very stupid question, but please keep in mind that this is my first web development and programming project
I am developing a CV maker site
I made this interface using a predefined template: and as soon as the user logs in in I redirect to another myResume.php page where they must enter their information, and, behold, here interface . Now my question is, how am I supposed to track the user after logging in? I mean, how can I make sure no one sees this page unless they are logged in first? Using my design, anyone can see the myResume page using a specific url like: http://www.example.com/myResume.php
Reformatting, is it possible to restrict myResume.php redirection to only from login.php file?

Thanks you

+3


source to share


3 answers


I just did it like 2 days ago for a site I am building.

So what you want to do is set up your session variables and check if they are there or not. I am assuming you have a login function function where it checks the database to see if the username and password are the same. If so, you send them to myResume.php

.

The next step is login.php

to set up a variable $_SESSION['user_id']

in php. This corresponds to the user session for the server session. This variable is a server side help with the access token stored in local cookies to match the user session. What is a session?

The next thing you need to do is add an if and a header for each file on your site, which should only be allowed access to registered users.



session_start();
if(empty($_SESSION['user_id'])){
    header('Location: login.php');
}

      

If you want to log out, you do something like this. You post them to logout.php, and in logout.php you just have this statement.

session_start();
session_destroy();
header('location: login.php');

      

you should always start a session on every page before you can, use, set, destroy session variables.

+2


source


The answer is session: PHP Guide to Sessions

It allows you to store information available to your scripts as your user navigates from page to page.



See tutorial on tiztag sessions or tutorial site on sessions

HTH

+2


source


Use session cookies. Here are some places to look ... http://php.net/manual/en/features.cookies.php , http://www.tuxradar.com/practicalphp/10/

+1


source







All Articles