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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Smackie
Forum Contributor
Posts: 302
Joined: Sat Jan 29, 2005 2:33 pm

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

Post 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
jmrdeuce32
Forum Newbie
Posts: 15
Joined: Wed Apr 27, 2005 5:45 pm
Location: Naples, FL

Post 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
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post 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.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Post 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
}
Post Reply