Jump to content

Recommended Posts

the script to actually fetch from the database the user thats trying to do admin stuff has a privilege of 10

i want a file called check.php

and basically i want it to be run before doing any admin tasks

and 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
Link to comment
https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42012
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42033
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42057
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42111
Share on other sites

Very interesting... so will this work...

[code]
<?php
session_start();
?>
<?php

/*
submit news script made by dann for access
from the admin panel
admin/
*/

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 statement
echo "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.
Link to comment
https://forums.phpfreaks.com/topic/11231-privileges/#findComment-42130
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.