Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- cookie check
- -------------------
- <?
- // Connects to your Database
- require("dbconfig.php");
- //checks cookies to make sure they are logged in
- if(isset($_COOKIE['ID_my_site']))
- {
- $username = $_COOKIE['ID_my_site'];
- $pass = $_COOKIE['Key_my_site'];
- $check = mysql_query("SELECT * FROM users WHERE user = '$username'")or die(mysql_error());
- while($info = mysql_fetch_array( $check ))
- {
- //if the cookie has the wrong password, they are taken to the login page
- if ($pass != $info['password'])
- { header("Location: index.php");
- }
- //otherwise they are shown the admin area
- else
- {
- }
- }
- }
- else
- //if the cookie does not exist, they are taken to the login screen
- {
- header("Location: index.php");
- }
- ?>
- login.php
- -------------------------------
- <?php
- require("dbconfig.php");
- $un=$_POST['username'];
- $pw=$_POST['password'];
- $query = mysql_query("SELECT * FROM users WHERE user ='$un' AND password='$pw'",$link);
- $count=mysql_num_rows($query);
- // If result matched $myusername and $mypassword, table row must be 1 row
- if($count==1){
- // Register $username, $password and redirect to file "login_success.php"
- session_register("un");
- session_register("pw");
- // if login is ok then we add a cookie
- $_POST['username'] = stripslashes($_POST['username']);
- $hour = time() + 3600;
- setcookie(ID_my_site, $_POST['username'], $hour);
- setcookie(Key_my_site, $_POST['password'], $hour);
- //then redirect them to the members area
- header("Location: index2.php");
- }else{
- header("Location: index.php");
- }
- ob_end_flush()
- ?>
Add Comment
Please, Sign In to add comment