Jump to content

Filter users using data from a database using $_Session


oliver12

Recommended Posts

Hi there. Im quite stuck at the moment and have no idea how to do this function. For my website I need to limit some users (players) to some sites and captains to other sites. I have a database using phpmyadmin, a table called players which stores both captains and players. There is a field called player_captain which is a varchar and contains either the value 'player' or 'captain' per user. How would I filter the users so they could go on certain pages.

 

<?php
//creates a session for the user
session_start();
//Checks if the user has a user_id
if(!isset($_SESSION["player_id"]))
{
//If user does not have user_id they are returned to the loginform page
header("Location: nocaptainaccess.php");
exit();
}
?>

 

I am quite a php noob as you can probably tell so any advice would great.

 

Thank you

 

Oli

<?php

if(mysql_num_rows(mysql_query("select * from players where player_id='" . $_SESSION['player_id'] . "' and player_captain='player' limit 0, 1")) == 1) {

   //Redirect to player site
   header('Location: example.com');

}

?>

 

And do the same for the captain one as well.

Thank you for the quick reply. I've added the 'require "dbconn.php";' to connect the database however im guessing I need to connect to the mysql query to the dbconn.php.

 

Previous code i've done it like this

<?php
require "dbconn.php";
$sql = "SELECT * FROM players WHERE player_id = '$_SESSION[player_id]'";
$result = mysql_query($sql, $connection)
or die ("Couldn’t perform query $sql <br />".mysql_error());
?>

 

How would i connect it? Sorry for the noob questions, im rubbish with 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.