Reaper0167 Posted January 2, 2009 Share Posted January 2, 2009 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. Link to comment https://forums.phpfreaks.com/topic/139156-only-letting-a-logged-in-user-to-a-certain-page-question/ Share on other sites More sharing options...
redarrow Posted January 2, 2009 Share Posted January 2, 2009 dont get you sorry. is your website only for users to upload images/. Link to comment https://forums.phpfreaks.com/topic/139156-only-letting-a-logged-in-user-to-a-certain-page-question/#findComment-727835 Share on other sites More sharing options...
redarrow Posted January 2, 2009 Share Posted January 2, 2009 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; } ?> Link to comment https://forums.phpfreaks.com/topic/139156-only-letting-a-logged-in-user-to-a-certain-page-question/#findComment-727838 Share on other sites More sharing options...
Reaper0167 Posted January 2, 2009 Author Share Posted January 2, 2009 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. Link to comment https://forums.phpfreaks.com/topic/139156-only-letting-a-logged-in-user-to-a-certain-page-question/#findComment-727856 Share on other sites More sharing options...
revraz Posted January 2, 2009 Share Posted January 2, 2009 On your login page, set a session. On your secured page, check that session. Link to comment https://forums.phpfreaks.com/topic/139156-only-letting-a-logged-in-user-to-a-certain-page-question/#findComment-727859 Share on other sites More sharing options...
redarrow Posted January 2, 2009 Share Posted January 2, 2009 <?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... Link to comment https://forums.phpfreaks.com/topic/139156-only-letting-a-logged-in-user-to-a-certain-page-question/#findComment-727867 Share on other sites More sharing options...
DarkWater Posted January 2, 2009 Share Posted January 2, 2009 redarrow, absolutely none of your posts have made a bit of sense. Link to comment https://forums.phpfreaks.com/topic/139156-only-letting-a-logged-in-user-to-a-certain-page-question/#findComment-727878 Share on other sites More sharing options...
lokie538 Posted January 2, 2009 Share Posted January 2, 2009 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" ); ?> Link to comment https://forums.phpfreaks.com/topic/139156-only-letting-a-logged-in-user-to-a-certain-page-question/#findComment-727899 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.