Depending on the visitors session condition whether user is 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.
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";
}
require "check.php";
Inside the check.php file we will keep this code.
<?Php
if(!(isset($_SESSION['userid']) and strlen($_SESSION['userid']) > 2)){
echo "Please <a href=g_login.php>login</a> to use this page ";
exit;
}else{
echo "Welcome $_SESSION[userid] | <a href='logout.php'>Logout</a>|<a href='change.php'>Change Password</a>";
}
?>
Now we can included the check.php file from our ( at top of )all required secure pages.
require "check.php";
Login Script
Signup Form Change Password
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.
| Moses | 24-10-2014 |
| I am new to php.Could you explain the database part too please. | |