SQL PHP HTML ASP JavaScript articles and free scripts to download

PHP Login and logout script and example

Depending on the visitors session condition whether logged in or not we can display different messages to the members.We should show an welcome messages to a logged in user like "Welcome john" with a logout button. Same way we if the member has not logged in then we can show login input box in that place or show the link to login page.

We can check the visitors session variable and display a login or logout link using one PHP IF condition. This is one example of php if and see detail Login script for full code. We will be using PHP isset function to check the existence of session variable.

Read more on PHP Session variables here

There are two types of pages here.
One is where based on user status ( login or not login) we will display welcome message with logout link and for other login link. For example the home page of the site where member is not yet logged in but can check the content of the page
if((isset($_SESSION['userid']) and strlen($_SESSION['userid']) > 5)){
 echo "Welcome $_SESSION[userid]  <a href=setting.php>Settings</a> . <a href=logout.php>Logout</a>";
}else{
echo "<a href=signup.php>Sign UP</a>  <a href=login.php>Login</a>";
}
Second one is for the pages where content can be accessed only by login members. So if the page is opened without login then we will not execute the content of the page and we will show the link to login page with a message. For example change password page or update profile page.
if((isset($_SESSION['userid']) and strlen($_SESSION['userid']) > 5)){
// Content of the page
}else{
echo "Please <a href='login.php?redirect=post.php'>Login</a> to post any topics";
}

Google+
Post Comment This is for short comments only. Use the forum for more discussions.
Name
Email( not to be displayed)Privacy Policy
1+2=This is to prevent automatic submission by spammers. Please enter the result of the sum as asked



Join Our Email List
Email:  
For Email Newsletters you can trust
HTML . MySQL. PHP. JavaScript. ASP. Photoshop. Articles. FORUM Contact us

©2000-2014 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer