Well recently i took upon a task.Which needed me to make an authentication function/system for it, and well.... i thought i'd go into an old project and use that one.... but.... then i found out... that my sister had gotten onto the computer and DELETED ALL OF MY PROJECTS!!!!!!!!!!!!!!!!!!!!
sooo...here i am.lol
My problem is this.
I am trying to create an authentication system.Pretty basic explanation i know.
When your not logged in. It works fine.But...
For some reason when i use this code in my index.php page(Shown below).
To determine if the user should be able to view the page(when logged in) or not. It will show the "You do not have a high enough rank to view this page."
aswell as the content that shouldnt be able to be viewed by the user.
Here Are the files.
Config.php Not included As it's just the SQL connection.Atm.
Index.php
I remember at least this much.On how to call the function in the index.php.PHP Code:<?php
session_start();
require("functions.php");
if(Authentication(5)){
print("Welcome");
}
?>
this is my functions.php page
Any Help is apperciated.PHP Code:<?php
include("config.php"); //Includes the connection to the database
error_reporting(E_ALL ^E_WARNING ^E_NOTICE);
// Start Authentication Functions
function Authentication($mRank){
// Authentication Functrion
if(isset($_POST['AuthLogin'])){
$result = mysql_query("SELECT * FROM users WHERE username='".$_POST['userName']."' AND password='".$_POST['passWord']."'");
extract($userinfo = mysql_fetch_object($result));
$_SESSION['CuSeR'] = $userinfo->username;
$_SESSION['CuSeR_ID'] = $userinfo->ID;
$_SESSION['CuSeR_Rank'] = $userinfo->rank;
$_SESSION['CuSeR_LastLogin'] = $userinfo->lastlogin;
}
//*
$result = mysql_query("SELECT * FROM users WHERE username='".$_SESSION['CuSeR']."'");
extract($userinfo = mysql_fetch_object($result));
print("My Rank:".$userinfo->rank."<br />");
print("Needed Rank:".$mRank."<br />");
if($userinfo->rank >= $mRank){
//return true;
if(!$userinfo->ID){
//return false;
return loginForm();
}
}else{
//return false;
return print("You do not have a high enough rank to view this page.<br />\n");
}
}//End Authentication Function
function loginForm(){
?>
<form action="index.php?module=Login" name="AuthLoginForm" method="post">
<table width="15%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#000000">
<tr>
<td colspan="2" bgcolor="#999999"><div align="center">Login</div></td>
</tr>
<tr>
<td width="8%" bgcolor="#999999">Username</td>
<td width="92%" bgcolor="#999999"><input name="userName" type="text" value="UserName" class="login_text" /></td>
</tr>
<tr>
<td bgcolor="#999999">Password</td>
<td bgcolor="#999999"><input name="passWord" type="password" value="Password" class="login_text" /></td>
</tr>
<tr>
<td colspan="2" bgcolor="#999999"><div align="center">
<input type="submit" name="AuthLogin" value="Submit" />
</div></td>
</tr>
</table>
</form>
<?
}
?>
Not to put any pressure on anyone but.. i have till saturday to finish.
I had this project sprung on me without notice.T'is hard to say no. You know...




Reply With Quote