oliver12 Posted March 28, 2010 Share Posted March 28, 2010 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 Link to comment https://forums.phpfreaks.com/topic/196822-filter-users-using-data-from-a-database-using-_session/ Share on other sites More sharing options...
GetPutDelete Posted March 28, 2010 Share Posted March 28, 2010 <?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. Link to comment https://forums.phpfreaks.com/topic/196822-filter-users-using-data-from-a-database-using-_session/#findComment-1033245 Share on other sites More sharing options...
oliver12 Posted March 28, 2010 Author Share Posted March 28, 2010 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. Link to comment https://forums.phpfreaks.com/topic/196822-filter-users-using-data-from-a-database-using-_session/#findComment-1033259 Share on other sites More sharing options...
oliver12 Posted March 28, 2010 Author Share Posted March 28, 2010 Nevermind first post, me being an idiot. Forgot to add the dbconn before session start. Thanks again the help. Link to comment https://forums.phpfreaks.com/topic/196822-filter-users-using-data-from-a-database-using-_session/#findComment-1033272 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.