Jump to content

php login


lukerodham

Recommended Posts

hi guys me again. kinda stuck, im trying to turn my admin login script in to a user login with the admin side of things, so to keep things separate. for some reason the include function is not working after its checked, if the user is a admin or not. any ideas on why this would not work? have i done something completely wrong or just missing something.

 

ive left the code below, if it helps aswell the login.php is a included file aswell to index.php.

 

thanks in advance.

 

login.php


<?php

$userback = $_SESSION['user'];
$username = $_POST['username'];
$password = md5($_POST['password']);
$login = $_post['submit'];

mysql_connect("db2700.oneandone.co.uk","dbo363845380","notgonnalie12");
mysql_select_db("db363845380") or die(mysql_error());

session_start(); 
if($_SERVER['QUERY_STRING'] == "logout") {
unset($_SESSION['user']);
header("Location: " . $_SERVER['PHP_SELF']);
exit;
}
if(!isset($_SESSION['user'])){
    if(!$submit){
   echo"<div align='center'><b>Please login</b></div><br>";
   echo "
        <html>
        <body>
        <div align='center'>
        <form method='post' action='".$_SERVER['REQUEST_URI']."'>
        <label>username: 
        <input type='text' name='username' id='username'>
        <label>password: 
        <input type='password' name='password' id='password'>
        </label>
        <label>
        <input type='submit' name='submit' id='submit' value='submit'>
        </label>
        </form>
        </div>
        </body>
        </html>
        ";	
}
    else {
        $rows = mysql_num_rows(mysql_query("SELECT * FROM users WHERE username='".mysql_real_escape_string($username)."' AND password='".mysql_real_escape_string($password)."'"));
        if($rows>0){
            while ($row = mysql_fetch_assoc($rows)){
                $_SESSION['user']="$username";
            
                $adminpass = $row['admin'];
            
                if($adminpass>=1){
                    include ("admin/index.php");
                }
                else {
                    echo "welcome $user1 you'll be directed in a few seconds.<br> if this doesn't happen please click here.";
                }
            }
        }
        else {
            if($rows<1){
                echo "Sorry no user information found. Please make sure details are correct.";
            }
        }
    }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/233638-php-login/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.