Page 1 of 1

Admin Button only.......!!

Posted: Wed Apr 27, 2005 8:03 pm
by Smackie
Im having a bit of a problem making a link just for the admin.. I want it where admin can go to the admin page while logged in instead of having to logout and logging back in i have it where the admin logs in same login as the users but the main problem is i dont know how to make a link so only admins can see... because my menu is in html not in php and im using sessions and i dont know if there is different ways of making a admin link so here is a look at the login script if that helps you any....


And also i would like to have a remember me check box put on this script as well and well every time i try doing it it gives me an error i dont know if im doing the if statement right or not.....

Code: Select all

<?php
ob_start();
// dBase file
include "dbConfig.php";

if ($_GET["op"] == "login")
                {
	if (!$_POST["username"] || !$_POST["password"])
		{
		die("Please go back and Supply a username and password.");
		}

	// Create query
	$q = "SELECT * FROM `dbUsers` "
		."WHERE `username`='".$_POST["username"]."' "
		."AND `password`=PASSWORD('".$_POST["password"]."') "
		."LIMIT 1";
	// Run query
	$r = mysql_query($q);

	if ( $obj = @mysql_fetch_object($r) )
	{
		// Login O.K., create session variables
		$_SESSION["valid_id"] = $obj->id;
		$_SESSION["valid_user"] = $_POST["username"];
		$_SESSION["valid_time"] = time();

	// Redirect to member page
	Header("Location: http://www.hauntedgraveyard.net/members.php");
                 	}
	else
		{
		// Login not successful
		die("Sorry, could not log you in. Wrong login information.");
		}
	                }
                else
		{
		echo "<form action=\"http://www.hauntedgraveyard.net/login.php?op=login\" method=\"POST\">";
		echo "Username: <input name=\"username\" size=\"15\" color=\"#FF0000\"><br />";
		echo "Password: <input type=\"password\" name=\"password\" size=\"15\"><br />";
		echo "<input type=\"submit\" value=\"Login\">";
		echo "</form>";
		}

?>


Thank You
Smackie

Posted: Wed Apr 27, 2005 8:16 pm
by jmrdeuce32
I think you will have to make your menu a PHP page....

If it is a just certain username that is the admin make a script that produces the link if the username is the admin.


Start the session at the top of the page and then just insert the following where the link would go in the middle of the HTML:

Code: Select all

<?php
if($_SESSION['username']=='admin'){
echo '<a href="yourlink">Admin Page</a>';
}
?>
Then in the admin page check the same thing.

I'm having troubles with sessions right now so this may not be of any help.

For the check box use:

Code: Select all

if(isset($_POST['checkbox'])){
   //stuff
}
Jcart | Please review Posting Code in the Forums

Posted: Thu Apr 28, 2005 12:00 am
by ol4pr0
You might want to think of using javascript.

It seems it bit Grr.. but i have found it actually handy, just check if certen variables are set. If not just dont process it @ all.

Posted: Thu Apr 28, 2005 9:42 am
by malcolmboston
javascript is pointless in this case, PHP is meant to handle this.

something like:

Code: Select all

if ($_SESSION['access_level'] == "admin")
{
   // print admin link
}