PHP Login Example with session
In this example you have create 2 PHP files .
File Name : index.php
<?php
session_start(); //start session
if(isset($_POST['click']))
{
$_SESSION['user']=$_POST['username']; //set value of username in session varible
header("Location:file2.php");
exit;
}
?>
<html>
<body>
<form method="post">
<input type="text" placeholder="Enter Username" name="username"/><br/>
<input type="password" placeholder="Enter Password" name="password" /><br/>
<input type="submit" name="click" value="Click Here">
<input type="reset" name="cancel" value="Cancel">
</form>
</body>
</html>
File Name : file2.php
<?php
session_start();
echo "WELCOME ".$_SESSION['user'];
?>
File Name : index.php
<?php
session_start(); //start session
if(isset($_POST['click']))
{
$_SESSION['user']=$_POST['username']; //set value of username in session varible
header("Location:file2.php");
exit;
}
?>
<html>
<body>
<form method="post">
<input type="text" placeholder="Enter Username" name="username"/><br/>
<input type="password" placeholder="Enter Password" name="password" /><br/>
<input type="submit" name="click" value="Click Here">
<input type="reset" name="cancel" value="Cancel">
</form>
</body>
</html>
File Name : file2.php
<?php
session_start();
echo "WELCOME ".$_SESSION['user'];
?>
Comments
Post a Comment