Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //file: login.php
- ...
- if (!$_SESSION['username']) {
- ?>
- <br>
- <table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
- <tr>
- <form name="form1" method="post" action="checklogin.php">
- <td>
- <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
- <tr>
- <td colspan="3"> <strong> Belépés </ strong> </ td>
- </ TR>
- <tr>
- <td width="78"> Felhasználó </ td>
- <td width="6">: </ td>
- <td width="294"><input name="myusername" type="text" id="myusername"></ td>
- </ TR>
- <tr>
- <td> jelszó </ td>
- <td>: </ td>
- <td><input name="mypassword" type="password" id="mypassword"></ td>
- </ TR>
- <tr>
- <td> </ td>
- <td> </ td>
- <td><input type="submit" name="Submit" value="Login"></ td>
- </TR>
- </Table>
- </Td>
- </Form>
- </TR>
- </table><br>
- <?
- }
- else {
- print "Már be vagy jelentkezve<br>
- kijelentkezés <a href="127.0.0.1/logout.php">kacc</a>";
- };
- ...
- /*-------------------------------------------*/
- //file: checklogin.php
- <?php
- require_once("config.php");
- require_once("connect.php");
- ob_start();
- $tbl_name="users"; // Table name
- // Connect to server and select databse.
- mysql_connect("$mysql_host", "$mysql_user", "$mysql_pass")or die("cannot connect");
- mysql_select_db("$mysql_db")or die("cannot select DB");
- // Define $myusername and $mypassword
- $myusername=$_POST['myusername'];
- $mypassword=md5($_POST['mypassword']);
- // To protect MySQL injection (more detail about MySQL injection)
- $myusername = stripslashes($myusername);
- $mypassword = stripslashes($mypassword);
- $myusername = mysql_real_escape_string($myusername);
- $mypassword = mysql_real_escape_string($mypassword);
- $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
- $result=mysql_query($sql);
- // Mysql_num_row is counting table row
- $count=mysql_num_rows($result);
- // If result matched $myusername and $mypassword, table row must be 1 row
- if($count==1){
- // Register $myusername, $mypassword and redirect to file "login_success.php"
- session_start();
- $_SESSION['username'] = $myusername;
- $_SESSION['password'] = $mypassword;
- $_SESSION['time'] = time();
- header("location:login_success.php");
- }
- else {
- echo "Wrong Username or Password";
- }
- ob_end_flush();
- ?>
- /*-------------------------------------------*/
- //file: login_succes.php
- <?php
- session_start();
- if(!session_is_registered(myusername)){
- header("location:login.php");
- }
- $_SESSION["id"] = $id;
- $_SESSION["username"] = $myusername;
- $_SESSION["password"] = md5($_POST['mypassword']);
- $_SESSION["gmlevel"] = $gmlevel;
- ?>
- <html>
- <body>
- Login Successful
- </body>
- </html>
- <?
- ?>
- /*-------------------------------------------*/
- //file: logout.php
- <?
- session_start();
- session_destroy();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement