Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Watch Videos here >> https://youtu.be/HKOnzjkFUDY
- Here are the Codes.
- Databas Connection
- ---dbcon.php
- <?php
- mysql_select_db('tutorial',mysql_connect('localhost','root',''));
- ?>
- Home Page
- ---home.php
- <?php
- include('dbcon.php');
- Session_start();
- if(!isset($_SESSION['id']))
- {
- header('location:index.html');
- }
- ?>
- <html>
- <body>
- <?php
- $id=$_SESSION['id'];
- $result=mysql_query("Select * From account where id='$id'")or die(mysql_error);
- $row=mysql_fetch_array($result);
- ?>
- <h1>Hello!!, Welcome <?php echo $row['username'];?></h1> <br>
- <a href="logout.php">Logout</a>
- </body>
- </html>
- Login validation
- --login.php
- <?php
- include('dbcon.php');
- if(isset($_POST['submit']))
- $username=$_POST['username'];
- $password=$_POST['password'];
- $result=mysql_query("SELECT * FROM `tutorial`.`account` where username='$username' and password='$password' ") or die(mysql_error());
- $count=mysql_num_rows($result);
- $row=mysql_fetch_array($result);
- if($count > 0 )
- {
- session_start();
- $_SESSION['id']=$row['id'];
- header('location:home.php');
- }
- else
- {
- header('location:index.html');
- }
- ?>
- Log out
- ---logout.php
- <?php
- session_start();
- session_destroy();
- header('location:index.html');
- ?>
- Main index
- ---index.html
- <html>
- <body>
- <h1>Login form</h1>
- <form method="POST" action="login.php" style="width:40px">
- Username: <input type="text" name="username">
- Password: <input type="text" name="password">
- <input type="submit" name="submit">
- </form>
- </body>
- </html>
- Please Subscribe for more Videos tutorial.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement