how this can happen? Is there something wrong in the code that I created? or something wrong with my php.ini settings? ANYONE please help me..
for the detail, the following is the code that I created.
1. login.php - the login form that submit to checklogin.php
Expand|Select|Wrap|Line Numbers
- <html>
- <head>
- <title>Login</title>
- </head>
- <body>
- <form name="form1" method="post" action="checklogin.php">
- <dl>
- <dt>Username</dt>
- <dd><input type="text" name="username"></dd>
- <dt>Password</dt>
- <dd><input type="password" name="password"></dd>
- <dt></dt>
- <dd><input type="submit" name="Submit" value="Login"</dd>
- </dl>
- </form>
- </body>
- </html>
Expand|Select|Wrap|Line Numbers
- <?php
- session_start();
- $server = "localhost";
- $username = "root";
- $password = "root";
- $db_name = "ecommerce";
- $db = mysql_connect($server,$username,$password) or DIE("connection failed !!");
- mysql_select_db($db_name) or DIE("no database !!");
- $login = mysql_query("select * from login where (username = '".$_POST['username']."') and (password = '".md5($_POST['password'])."')",$db);
- $rowcount = mysql_num_rows($login);
- if ($rowcount == 1){
- $_SESSION['username'] = $_POST['username'];
- header("Location: index.php");
- }
- else
- {
- header("Location:login.php");
- }
- ?>
Expand|Select|Wrap|Line Numbers
- <?php
- session_start();
- if (!isset($_SESSION['username'])){
- header("Location:login.php");
- }
- echo"login success, this is index.php page<br>";
- echo"welcome, user<br>";
- echo"<a href=\"logout.php\">logout</a>";
- ?>