PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY Using (Web design service)
PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY Using sessions to restrict access The first words that probably come to mind when thinking about restricting access to a website are username and password. Although these generally unlock entry to a site, neither is essential to a session. You can store any value as a session variable and use it to determine whether to grant access to a page. For instance, you could create a variable called $_SESSION[’status’] and give visitors access to different parts of the site depending on its value, or no access at all if it hasn t been set. A little demonstration should make everything clear, and show you how sessions work in practice. PHP Solution 9-1: A simple session example This should take only a few minutes to build, but you can also find the complete code in session01.php, session02.php, and session03.php, in the download files for this chapter. 1. Create a page called session01.php in a new folder called sessions in the phpsolutions site root. Insert a form with a text field called name and a submit button. Set the method to post and action to session02.php. The form should look like this:
2. In another page called session02.php, insert this above the DOCTYPE declaration: The inline comments explain what s going on. The session is started, and as long as $_POST[’name’] isn t empty, its value is assigned to $_SESSION[’name’]. 3. Insert the following code between the
tags in session02.php: Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.