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? Link to comment https://forums.phpfreaks.com/topic/91286-creating-admin-area/ 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"; } Link to comment https://forums.phpfreaks.com/topic/91286-creating-admin-area/#findComment-467809 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 Link to comment https://forums.phpfreaks.com/topic/91286-creating-admin-area/#findComment-467816 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 Link to comment https://forums.phpfreaks.com/topic/91286-creating-admin-area/#findComment-467819 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 Link to comment https://forums.phpfreaks.com/topic/91286-creating-admin-area/#findComment-467826 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 Link to comment https://forums.phpfreaks.com/topic/91286-creating-admin-area/#findComment-467828 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 Link to comment https://forums.phpfreaks.com/topic/91286-creating-admin-area/#findComment-467835 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... ?? Link to comment https://forums.phpfreaks.com/topic/91286-creating-admin-area/#findComment-467838 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. Link to comment https://forums.phpfreaks.com/topic/91286-creating-admin-area/#findComment-467840 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.