Skip to content
Ebhor.com

Ebhor.com

  • Business Studies
  • Tutorial
    • Spring Tutorial
    • Bootstrap Tutorial
    • The Ultimate CSS Tutorial
    • Mathematics Tutorial
    • JavaScript Tutorial
    • Struts1 Tutorial
    • Hibernate Tutorial
    • JSP Tutorial
    • Best Jquery tutorial
    • CSS
  • Java
  • Php
  • Full form
  • Iot
  • Practice

PHP Session Example

February 12, 2023July 8, 2018

The previous post was about PHP Session There explained about session its purpose and syntax in detail. Let’s see one good example of the session.

User login system
1. connection.php
This page is used to establish a database connection from the application.


2. index.php
This page retrieves the user detail from the database

query($sql);
		$num = $res->num_rows;
		if($num!=0)
		{
			$row = $res->fetch_array();
            			$_SESSION[userid] = $row[id];
			$_SESSION[chk]    = true;
            			header("location:profile.php");  //redirect one PHP file to another PHP file
		}
		else
		{
			echo "Login Fail";
		}

	}
?>;

 

Email-
Password

New User

 

3.

query($sql);
		header("location:index.php");
	}
?>

 

Name-
Address-
Phone-
Email-
Password

Already Register

 

4. checking.php
Check whether the user is in session or not


5. profile.php
This page displays the user information on the page

To select this select * from user query is used and we passed session userid that is extracted from $_SESSION[]

query($sql);
		$row = $res->fetch_array();
		echo "
$row[name]$row[address]$row[phone]$row[email]
";
		
		echo "
		      Change Password";
	
?>

6. header.php
This page starts the session and shows a link login or logout based on user session was created or not

Login'; } else{ echo 'Logout'; } ?> Profile

7.logout.php
This page is used to destroy the session


8. change.php
This page is used to change the user’s password

query($sql);
		$num = $res->num_rows;
		if($num!=0)
		{
			if($_POST[np]==$_POST[cp])
			{
				$sql1 = "update user set password = '$_POST[np]' where id='$_SESSION[userid]'";
				$con->query($sql1);
				header("location:logout.php");
			}
			else
			{
				echo "Password Does not Matched";
			}
		}
		else
		{
			echo "Current Password Wrong";
		}
	}
?>

 

Current Password-
New Password-
Confirm Password-

Profile

 

Categories php Tags login example, php, session

Pages

  • About Us
  • Contact Us
  • Disclaimer
  • Guest Post
  • Privacy Policy

Categories

  • Amazon Corretto (1)
  • android (3)
  • angular (3)
  • angularjs (1)
  • article (3)
  • Blockchain (4)
  • bootstrap (45)
  • Business Studies (12)
  • C (6)
  • c language (1)
  • C Programming (45)
  • C++ (41)
  • census (1)
  • chhattisgarh (1)
  • computer graphics (6)
  • computer-basics (3)
  • computer-networks (3)
  • Cryptocurrency (1)
  • CSS (53)
  • full form (8)
  • gk (2)
  • google (1)
  • gst (1)
  • Hibernate (7)
  • hql (1)
  • hr (1)
  • html (15)
  • IoT (1)
  • java (115)
  • javascript (42)
  • jdbc (1)
  • jpa (1)
  • jquery (13)
  • json (2)
  • linux (20)
  • Machine Learning (1)
  • maths (52)
  • Minecraft (1)
  • mysql (27)
  • php (40)
  • python (7)
  • reactjs (1)
  • scilab (2)
  • seo (1)
  • servlet (17)
  • solved (3)
  • spring (11)
  • spring boot (5)
  • struts2 (10)
  • symbol (1)
  • toc (1)
  • tools (1)
  • Uncategorized (10)
  • verilog (2)
  • XAMPP (3)

Latest Posts

  • Java Program to Add Two Numbers Using Methods (With and Without Return Value)
  • Python Examples
  • How to Reverse a String in Java (7 Ways)
  • HTML del tag
  • Window.resizeTo() in javascript
  • 21 to 30 Table And Easy Methods To Memorize Times Table
  • SpringBoot JPA @OneToMany Mapping : Fetch data from tables
  • SETS
  • Functions in PHP
  • Adding Two Numbers in Python: A Step-by-Step Guide

Copyright By Ebhor.com 2022