The session () function was studied:
1, visitors into the site to browse a post, he wants to comment! Then the page jumps to the login.php login interface! How is this achieved?? The principle of seeking!!
2, the user login post, PHP How to know which registered users posted! How did this come true? The principle of seeking!
Reply to discussion (solution)
User Registration, registration information physical examination to the database by querying the database to achieve.
After the user logs in, the user name is stored in session
Check the session for login information when commenting
PHP does not know which registered user posted the post
You need to associate your user name with your post.
It's not a thorough study.
Log in the session after the user ID, in other words not logged in the ID also does not exist in the session variable inside, you can judge jump
According to SessionID to be that user, the information full report exists in the session, the time obtained according to SessionID
According to SessionID to be that user, the information full report exists session inside, get the time according to SessionID ' that show post page PHP How to know who sent the post? Thank you
According to SessionID to be that user, the information full report exists session inside, get the time according to SessionID ' that show post page PHP How to know who sent the post? Thank you
Read database Fields ...
The session () function was studied:
1, visitors into the site to browse a post, he wants to comment! Then the page jumps to the login.php login interface! How is this achieved?? The principle of seeking!!
2, the user login post, PHP How to know which registered users posted! How did this come true? The principle of seeking!
I've seen Hanshunping's PHP video talk about the problem you said, in his video, explaining the session, a case, that is how to prevent the user illegal login, should be the question you are now consulting.
1. When the user logs in, the user's login name and password (which is ignored by the verification code) will be uploaded to the server via the form, which is the corresponding PHP verification script. The script obtains the user table from the database for validation.
2. If the login name and password of the user are valid, then the PHP program (specifically responsible for jumping) will open the session mechanism (SESSION_START), save the user's login name to the session and jump. If it is not legal (login is not correct), then jump to the landing page, let the user re-enter the user name and password.
The code is as follows:
$adminService =new Adminservice ();
$name = $adminService->checkadmin ($id, $password);
if ($name) {
Legal
Session_Start ();
$_session[' Loginuser ']= $name;
Header ("Location:empmanage.php?name= $name");
If you want to jump, it is best to exit ();
Exit ();
}else{
Illegal
Header (' location:login.php?errno=1 ');
Exit ();
}
3. We create a public script, for example, called common.php, in which we define a method as follows:
function Checkuservalidate () {
Session_Start ();
if (Empty ($_session[' Loginuser ')) {
Header ("Location:login.php?errno=1");
}
}
4, in the need to prevent the user illegal login page (such as you say the posting page) to introduce such two sentences (these two words, put in the beginning of the page)
Require_once ' common.php ';
Checkuservalidate ();
Users who do not login are not able to enter the post page, if the login successful users into the page, then the program can easily get the user data from the session.
Do not know whether you understand now, if you want to know more detailed, you can watch Hanshunping video 119, the latter part of the case. No more writing, exhausted. Oh!