开发者

Restricting the access to specific pages

开发者 https://www.devze.com 2023-04-13 07:39 出处:网络
I\'m building a quiz web application.The functionality of the site is just about complete.However, I\'d like to create a script that allows me to input new quizzes and questions from my web browser as

I'm building a quiz web application. The functionality of the site is just about complete. However, I'd like to create a script that allows me to input new quizzes and questions from my web browser as opposed to manually inputting them into the MySQL database using phpMyAdmin.

I want to build a form called newquiz.php that will enable me to do the inputting on the browser but I don't want just anyo开发者_开发百科ne to come across it and start making changes to my database. So, my question is how should I go about limiting access to this specific page? In my Head First book they talk about using HTTP authentication but I haven't had any success with that (my attempt here: Unsucessfully accessing Admin page using HTTP authentication with PHP).

I'd love some guidance on this issue. Thanks!


Have a login function, that checks username/password to something you have stored in something like MySQL. Store the userid in $_SESSION['id'].

Now you can start the limited website with the php=code:

if(!isset($_SESSION['id'])) die("you are not able to view this without logging in");

and the rest of your code underneath


One can also redirect to unauthorized user to Website login page to restrict unauthorized access by following:

On any .php page you want to restrict access:

if(!isset($_SESSION['id'])) {
    header("Location:index.php");
}
else
{
    //continue adding your quiz to your page.
}


The easiest way to do this is to use your web server's built-in authentication mechanism. Apache has .htaccess files; other web servers have different solutions.

0

精彩评论

暂无评论...
验证码 换一张
取 消