does any one no how can i restrict access to a particular page i created this session after the user is logged in $_SESSION['username'] = $user; PHP: thank you
Who do you not want to access the page? If you only want logged in users to have access to it, add this to beginning of the page: <?php session_start(); if(!isset($_SESSION['username'])) { die("You do not have permission to access to this page."); } ?> PHP:
Or set a .htaccess user/pass on the file or folder: http://www.elated.com/articles/password-protecting-your-pages-with-htaccess/
The best idea is to set a column or status, or access in the database. Admin, Moderator, User, .... Once user logs in, set $_SESSION['status']=$status and use this. This way, you can set certain users that can access certain pages.
Here is a quick code for you. <?php if($_COOKIE['site_cookie']=='true') { //Page Content exit; } else { if(isset($_POST['submitted'])) { setcookie('site_cookie','true',time()+60*60*24); } else { } } <html> <head> <title>Restricted Page</title> </head> <body> <form action="page.php" method="post"> <b>Page Is Restricted</b><br /> Password: <input type="password" name="password" /> <input type="hidden" name="submitted" value="true" /> <input type="submit" value="Enter Page!" /> </form> </body> </html> Code (markup): However cookies are insecure and I would advise you if you are keeping really secret information in here and/or the page is easy to find than use sessions and a more complex system.