Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE HTML>
- <html>
- <head>
- <!-- title of the web page-->
- <title>Login</title>
- <!--webpage metatags -->
- <meta charset="utf-8" />
- <!--specific web page meta tags-->
- <!--CSS links-->
- <link rel="stylesheet" rel="text/css" href="style.css" />
- </head>
- <body>
- <!--register users-->
- <form name="register" method="post"
- action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" >
- <strong> Login</strong><br /><br />
- User name:
- <input type="text" name="username"><br /><br />
- Password:
- <input type="text" name="password"><br /><br />
- <input type = "submit" value ="Register" />
- </form>
- <?php
- // statistics
- session_start(); // start of the session
- // the first time you visit
- $fileLocation="stats/login.txt";
- if(!isset($_SESSION['counter'])) {
- // open the file
- $file = fopen($fileLocation, "r");
- if(!$file){
- echo "Could not open the file" ;
- }
- else {
- // read the file and get the counter
- $counter = ( int ) fread ($file,20) ;
- fclose ($file);
- $counter++ ;
- echo" <p> Visitor Count: ". $counter . " </p> " ;
- $file = fopen($fileLocation, "w" ) ;
- fwrite($file,$counter) ;
- fclose ($file) ;
- $_SESSION['counter'] = $counter;
- }
- } else { // It's not the first time, do not update the counter but show the total hits stored in session
- $counter = $_SESSION['counter'];
- echo" <p> Visitor Count: ". $counter . " </p> " ;
- }
- //validate registration form
- if((empty ($_POST['username'])) OR (empty($_POST['password'])))
- {
- //if the values are empty -
- echo "<br/> Please fill in all the above inputs";
- }else{
- echo "<br> Process Validation";
- //if the inputs has values
- //store the data into local variables
- $Uname = $_POST['username'];
- $Pname = $_POST['password'];
- $Check=true;
- //validate Username as email address
- //validate password - more then 5 char
- if (strlen($Pname) <5 )
- {
- echo "<br> Username or password is incorrect";
- //open error_log.txt as append
- $File="error_log.txt";
- $OpenFile = fopen($File, 'a');
- $ip = $_SERVER['REMOTE_ADDR'];
- $time = date("h:i:sa");
- $date = date("d/m/y");
- $error = 'incorrect name entered';
- $stringData = "$ip, $time, $date, $error\n";
- fwrite($OpenFile, $stringData);
- fclose($OpenFile);
- $Check=false;
- }
- //if all the validation are true then prepare
- //to store to online database table
- if ($Check == true)
- {
- echo "<br>Checking.....</br>";
- require_once('db.php');//connect the database
- $SQL = "SELECT * FROM user WHERE username = '$Uname' and password= '$Pname'";
- $result = $conn->query($SQL); //execyte the SQL query. Store the data in $result as an array.
- if ($result->num_rows >0)
- {
- //the users information is available in the database.
- echo "<br> Login Successful";
- echo "<br><br> re-direct to members page";
- header ( 'refresh:5; url=member.php?id='.$Uname);// re-directs to the member page after 5 sec delay.
- }
- else {
- // The users information has not been found.
- echo "<br> Username or Password incorrect";
- }
- }
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement