runnerjp Posted February 15, 2008 Share Posted February 15, 2008 hey i am going about to creat and admin area... i want the link to only appear if the user with id=1 is on... and can only access the page if the users had the id of 1 i use $id = $_SESSION['user_id']; so get id.... how would i got abotu doing this? Quote Link to comment Share on other sites More sharing options...
marcus Posted February 15, 2008 Share Posted February 15, 2008 if($id == 1){ echo "<a href=\"/admin/index.php\">Admin Index</a>\n"; } // admin/index.php if($id != 1){ echo "You are not an admin and cannot be here!\n"; }else { echo "Welcome runnerjp!\n"; } Quote Link to comment Share on other sites More sharing options...
runnerjp Posted February 15, 2008 Author Share Posted February 15, 2008 wooow very fast reply haha thanks.. i will try it out Quote Link to comment Share on other sites More sharing options...
marcus Posted February 15, 2008 Share Posted February 15, 2008 just make sure you have $id defined on the pages that need it Quote Link to comment Share on other sites More sharing options...
runnerjp Posted February 15, 2008 Author Share Posted February 15, 2008 ok tried it...first bit works great <?php $id = $_SESSION['user_id']; if($id != 1){ echo "You are not an admin and cannot be here!\n"; }else { echo "Welcome runnerjp!\n"; } ?> this bit seems to not reconise that my id is 1 Quote Link to comment Share on other sites More sharing options...
marcus Posted February 15, 2008 Share Posted February 15, 2008 you don't have session_start(); on the top of the file Quote Link to comment Share on other sites More sharing options...
runnerjp Posted February 15, 2008 Author Share Posted February 15, 2008 oh boy im always forgetting that 1... ty for a ver quick fix haha Quote Link to comment Share on other sites More sharing options...
runnerjp Posted February 15, 2008 Author Share Posted February 15, 2008 sorry can i ask how secure this is... ?? Quote Link to comment Share on other sites More sharing options...
marcus Posted February 15, 2008 Share Posted February 15, 2008 very secure, sessions can't be controlled by the user. *1400th post, lol. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.