Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------- index.php Code --------------------------------
- <?php
- session_start();
- if (isset($_SESSION['logged']))
- {
- include "indexl.inc.php";
- }
- // Not Logged.
- else
- {
- include "indexnl.inc.php";
- }
- ?>
- ----------------------------- indexl.inc.php ----------------------------------
- <?php
- if (isset($_SESSION['logged']))
- {
- $username = $_SESSION['logged'];
- include "sql.php";
- $query = mysql_query("SELECT * FROM `users` WHERE username='$username'");
- $numrow = mysql_num_rows($query);
- if ($numrow == 0)
- {
- header("Location: index.php");
- }
- else
- {
- while ($row = mysql_fetch_array($query))
- {
- $name = $row['name'];
- $lastname = $row['lastname'];
- }
- }
- }
- else
- {
- header("Location: index.php");
- }
- ?>
- <html>
- <head>
- <title></title>
- </head>
- <body>
- <?php
- echo "Hello, $name $lastname<br />";
- echo " <a href=\"logout.php\">Logout</a>";
- ?>
- <p>
- <a href="index.php">Home</a> |
- <a href="profile.php">Profile</a>
- </p>
- </body>
- </html>
- -------------------------------- indexnl.inc.php ---------------------------
- <?php
- if (isset($_SESSION['logged']))
- {
- header("Location: index.php");
- }
- ?>
- <html>
- <head>
- <title></title>
- </head>
- <body>
- <form method="POST" action="">
- Username : <input type="text" name="username" />
- Password : <input type="password" name="password" />
- <input type="submit" name="submit" value="Login" />
- </form>
- <a href="register.php">Not a Member yet?</a>
- <?php
- if (isset($_POST['submit']))
- {
- if (empty($_POST['username']) || empty($_POST['password']))
- {
- echo "Username Or/And Password is empty.";
- }
- else
- {
- include "sql.php";
- $username = mysql_real_escape_string(ucwords(strtolower($_POST['username'])));
- $password = md5(strtolower($_POST['password']));
- $query = mysql_query("SELECT * FROM `users` WHERE username='$username'");
- $numrow = mysql_num_rows($query);
- if ($numrow == 0)
- {
- echo "Username Or/And Password is wrong.";
- }
- else
- {
- while ($row = mysql_fetch_array($query))
- {
- $rowusername = $row['username'];
- $rowpassword = $row['password'];
- }
- if ($username == $rowusername)
- {
- if ($password == $rowpassword)
- {
- // ---- Logged in ---- \\
- $_SESSION['logged'] = $username;
- header("Location: index.php");
- }
- else
- {
- echo "Username Or/And Password is wrong.";
- }
- }
- else
- {
- echo "Username Or/And Password is wrong.";
- }
- }
- }
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement