Jump to content

only letting a logged in user to a certain page question


Reaper0167

Recommended Posts

Would I have to change my register/login script to have members that are logged in view a specific page. This page would then allow them to upload images to my database. Or is there just a couple lines to put in each page that would say "if" logged in then "goto" page, and "if" not logged in "goto" login page. Can someone point me in the right direction.

your get the drift.

 

If you add a extra database field, call it permission.

 

Now every permission set from 0 - 1 .

 

example.

<?php

$sql="select * from users where id='$id'";
$res=mysql_query($sql)or die(mysql_error());

while($row=mysql_fetch_assoc($res)){

if($row['permission']==0){

	header('location: a_web_page.php');

}elseif($row['permission']==1){

	header('location: another_web_page.php');
}
}
?>

 

want to show only user with permission 1

<?php

$sql="select * from users where permission='1'";
$res=mysql_query($sql)or die(mysql_error());

while($row=mysql_fetch_assoc($res)){

echo $username;

}
?>

 

want to show only user with permission 0

 

// if you add to this and above id=$'id' the current user will only be allowed

to use the current page.

<?php

$sql="select * from users where permission='1'";
$res=mysql_query($sql)or die(mysql_error());

while($row=mysql_fetch_assoc($res)){

echo $username;

}
?>

sorry for the confusion,,, if a user is logged in, he/she could then have access to upload to a database or search the database. if the user is not registered and logged in then going to a page such as uploads or even search page would be restricted to them until they are registered and logged in.

<?php session_start();

$sql="select * from users";
$res=mysql_query($sql)or die(mysql_error());

while($row=mysql_fetch_assoc($res)){
   
   $SESSION['user_id']=$row['permission'];
}
?>

 

all pages not allowed to be seen....

 

<?php session_start();

if(!isset($_SESSION['user_id'])){

echo"SORRY BUT YOU NEED TO LOGIN TO ACCESS THIS PAGE.";

// or a header('location: what_ever_page to_go_to.php');

exit;
}

?>

 

start to make nice session functions now go for it...

I use this on my admin only pages!

<?php
session_start();

$host = "localhost";
$user = $_SESSION['user'];
$passwd = $_SESSION['passwd'];
$dbname = "******"; 

session_regenerate_id(true);

$cxn = mysqli_connect($host, $user,$passwd,$dbname) 
            or header ( "Location: wrong.php" );  
?>

 

 

Archived

This topic is now archived and is closed to further replies.

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