Jump to content

htaccess help needed


jamesmpollard

Recommended Posts

I was wondering if someone could shed some light on where I'm going wrong here. I'm trying to make it so that if a user came to my site (in dev mode at the minute so localhost) and used the url for example http://localhost/example/aquery/string.


The url it would actually access it http://localhost/example.php?route=aquery/string. Is this possible? Here's what I have so far...




Options All -Indexes +FollowSymLinks +MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)/(.*)$ $1.php?route=$2 [L]
DefaultType application/x-httpd-php


 

 

Any help appreciated.


Many thanks


James


Link to comment
Share on other sites

Rewrites are not for multiple user modes, it's for using the same values each time, modifying the url address versus the actual location.

 

Your best bet is to include different scripts or permission rights with code.

 

Use a session to see if that person has at least a certain permission level

User permissions 1-9 stored in database

Always use session_start(); top your scripts

 

Upon successful login when you do a query set the permission in the session

$_SESSION['permission'] = $row['permission'];

 

Now in your script can check if a permission is higher than a certain amount.

if($_SESSION['permission'] && $_SESSION['permission'] >= {
    //allow something a superadmin can do
}

You can also do some functions to make it simpler writing throughout your code.

Can expand upon this with specific roles hard coded or saved database

<?php
session_start();

//set session with login query
$_SESSION['permission'] = 9; //1-9

//permissions based on at least a certain number
function isUberAdmin()
{
    if ($_SESSION['permission'] && $_SESSION['permission'] == 9) {
        return true;
    } else {
        return false;
    }
}

function isSuperAdmin()
{
    if ($_SESSION['permission'] && $_SESSION['permission'] >=  {
        return true;
    } else {
        return false;
    }
}

function isAdmin()
{
    if ($_SESSION['permission'] && $_SESSION['permission'] >= 7) {
        return true;
    } else {
        return false;
    }
}

function isUberModerator()
{
    if ($_SESSION['permission'] && $_SESSION['permission'] >= 6) {
        return true;
    } else {
        return false;
    }
}

function isSuperModerator()
{
    if ($_SESSION['permission'] && $_SESSION['permission'] >= 5) {
        return true;
    } else {
        return false;
    }
}

function isModerator()
{
    if ($_SESSION['permission'] && $_SESSION['permission'] >= 4) {
        return true;
    } else {
        return false;
    }
}

function isUberUser()
{
    if ($_SESSION['permission'] && $_SESSION['permission'] >= 3) {
        return true;
    } else {
        return false;
    }
}

function isSuperUser()
{
    if ($_SESSION['permission'] && $_SESSION['permission'] >= 2) {
        return true;
    } else {
        return false;
    }
}

function isUser()
{
    if ($_SESSION['permission'] && $_SESSION['permission'] >= 1) {
        return true;
    } else {
        return false;
    }
}

function isLoggedIn()
{
    if ($_SESSION['permission'] && $_SESSION['permission'] != "") {
        return true;
    } else {
        return false;
    }
}


//simple usage
if (isAdmin()) {
    echo " are admin";
} else {
    echo " not admin";
}

if (isLoggedIn()) {
    echo " are logged in";
} else {
    echo " not logged in";
}

if (isUser()) {
    echo " are at least a user";
} else {
    echo " not even a user";
}
?>
Link to comment
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.