localhost Posted June 5, 2006 Share Posted June 5, 2006 alright so whenever any user signs up to my site their priv table is set to "1"i want this to be completely backended, i just want a script that will check for priv..and then an if statement likeif priv==1whatever}if priv==10echo " admin panel link";include('admin/');}you guys get it right? Quote Link to comment https://forums.phpfreaks.com/topic/11231-privileges/ Share on other sites More sharing options...
AndyB Posted June 5, 2006 Share Posted June 5, 2006 User login/passwordConnect to databaseRetrieve record (if doesn't exist, go back to login)If priv == 10 {// whatever admin stuff} else {// just do normal user stuff}... what specific problem do you have?? Quote Link to comment https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42007 Share on other sites More sharing options...
localhost Posted June 5, 2006 Author Share Posted June 5, 2006 the script to actually fetch from the database the user thats trying to do admin stuff has a privilege of 10i want a file called check.phpand basically i want it to be run before doing any admin tasksand i want it to check the user thats logged in, and their privilege wether its 1 or 10 and if its 10 to do certain things Quote Link to comment https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42012 Share on other sites More sharing options...
poirot Posted June 5, 2006 Share Posted June 5, 2006 Something like this will do:[code]if ($priv !== 10) { die();}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42018 Share on other sites More sharing options...
localhost Posted June 5, 2006 Author Share Posted June 5, 2006 true but the query...like$user = $_SESSION['user'];select username from $user if logged in user priv==10 do thisi cant really explain it better Quote Link to comment https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42030 Share on other sites More sharing options...
redarrow Posted June 5, 2006 Share Posted June 5, 2006 exsplain slowly in deatail what your doing and what you need to do.Do you need help with the select statement or what, as i can see the quistion has been ansawed. Quote Link to comment https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42032 Share on other sites More sharing options...
localhost Posted June 5, 2006 Author Share Posted June 5, 2006 I need to know the script that I can have that does this:- Checks the username- Then checks their privilege.The above 2 I need help with, the query's to check their username and what their privilege is.- Then I need to know how to use it in an if statement like some said, if($priv==10) {// do this} else {// do this}This way, I can start protecting the admin panel, and the news submission, etc. Quote Link to comment https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42033 Share on other sites More sharing options...
redarrow Posted June 5, 2006 Share Posted June 5, 2006 <? session_start();connect database$query="select username from $user where user='$user'"; $result=mysql_query($query);if(mysql_num_rows($result)==0) {echo "sorry login";}else{if($prv==10) {admin stuff}?> Quote Link to comment https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42042 Share on other sites More sharing options...
localhost Posted June 5, 2006 Author Share Posted June 5, 2006 like this:$query2 = "SELECT * FROM users WHERE username==$user AND priv==10";then it has the user logged in with a priv of 10...waitim lost, really confused...goddamn it Quote Link to comment https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42043 Share on other sites More sharing options...
redarrow Posted June 5, 2006 Share Posted June 5, 2006 [code]$query2 = "SELECT * FROM users WHERE username='$user' AND priv='10'";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42045 Share on other sites More sharing options...
localhost Posted June 5, 2006 Author Share Posted June 5, 2006 this is what i have:[code]// Define the current logged in persons username$user = $_SESSION['user'];// Select all usernames with the username of the currently logged in persons (1)$query = "SELECT * FROM users WHERE username=$user AND priv=10";$result = mysql_query($query) or die('Cannot select all users with a privilege of 10 out of logged in user.');// See how many match the above query, if it's 1, then they have admin privileges, if it's 0 they do not$num=mysql_numrows($result);if($num=1) {echo "You have sufficient administrative privileges.";} else {echo "You do not have the privileges for this.";}[/code]now to figure out how to just use an include before all admin activity Quote Link to comment https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42057 Share on other sites More sharing options...
poirot Posted June 5, 2006 Share Posted June 5, 2006 Simple, but functional.[code]$user = $_SESSION['user'];mysql_query("SELECT priv FROM users WHERE priv=10 AND username='$user'");if (mysql_num_rows == 0) { die();}[/code]Just remember to include this AFTER connecting to the database. If no rows are found, the script immediately stops execution. Quote Link to comment https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42111 Share on other sites More sharing options...
localhost Posted June 5, 2006 Author Share Posted June 5, 2006 Would that not work the same? also I would need session start and connect to db right?and then i could just put that on top of every form in the admin panel right? Quote Link to comment https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42117 Share on other sites More sharing options...
poirot Posted June 5, 2006 Share Posted June 5, 2006 Acutally, if the user is an admin, it does nothing; but if he/she isn't, it will abort the script.This should do what you need, I guess.And yes, you need to connect to the database and use session_start() Quote Link to comment https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42125 Share on other sites More sharing options...
localhost Posted June 5, 2006 Author Share Posted June 5, 2006 Very interesting... so will this work...[code]<?phpsession_start();?><?php/*submit news script made by dann for accessfrom the admin paneladmin/*/include('../includes/connect.php');$user = $_SESSION['user'];mysql_query("SELECT priv FROM users WHERE priv=10 AND username='$user'");if (mysql_num_rows == 0) { header('Location: ../index.php');} else {if($user) {if(isset($_POST['submit'])) {$username = $_POST['username'];$title = $_POST['title'];$description = $_POST['description'];$ip = $_POST['ip'];$date = $_POST['date'];if($title==NULL || $description==NULL) {echo "All fields must be filled in.";} else {$query = "INSERT INTO news (`username`, `title`, `description`, `ip`, `date`) VALUES ('$username', '$title', '$description', '$ip', '$date')";$result = mysql_query($query) or die('Could not insert news into system contact Copernicus');} // for submit button if} // for if is NULL} else { // for the logged in if statementecho "you must be logged in.";}} // for priv check?><style type="text/css"><!--.style1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: x-small;}--></style><form action="" method="POST"><title>Submit News</title><p><input type="hidden" name="username" value="<?php echo $_SESSION['user']; ?> " /> <Br> <span class="style1">Title:<Br> <input type="text" name="title" /> <input type="hidden" name="ip" value=" <?php echo $_SERVER['REMOTE_ADDR']; ?> "> <input type="hidden" name="date" value=" <?php echo date('m/d/Y'); ?> "> <BR> Description: <Br> <input name="description" type="text" value="" height="50"> <BR> <input type="submit" name="submit" value="Submit" /> </span></form> </span></p>[/code]BTW, Thanks for all your help. Quote Link to comment https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42130 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.