PHP Session Example
Previous post was about PHP Session There explained about session its purpose and syntax in detail. Lets see one good example of session. User login system 1. connection.php This page is used to establish database connection from application.
1 2 3 | <!--?php $con = new mysqli("localhost","root","","session"); ?--> |
2. index.php This page retrives the user detail from database
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <!--?php include "header.php"; include "connection.php"; if($_POST[em]) { $sql = "select * from `user` where `email`='$_POST[em]' and `password`='$_POST[pw]'"; $res = $con--->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
1 |