Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 26th, 2004, 04:25 AM
Authorized User
 
Join Date: Feb 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to knight
Default Autorized page Access

how can i restrict the user to view some pages without authorize access i think it is control via session if yes then how? and if other method pls tell me

 
Old February 26th, 2004, 06:16 AM
Authorized User
 
Join Date: Sep 2003
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It is possible to use sessions. DO this by ensuring every page has the code
Code:
<?php
session_start();
?>
BEFORE ANY OTHER code Then on your login.php page have a form that "logs the user in" by setting
Code:
<?php
$_SESSION['username'] = $_POST['username'];
//Any other information you want stored can go here as well, be 
//careful with passwords.
?>
The above code assumes your form method was "post" (If it was get, use $_GET) and the textbox containing the username was called username (Case sensitive) I recommend $_POST as it stops the user entering a known user name in the address bar and gaining access that way.

Then on each "protected" page something like the following, after the session_start();
Code:
if (!isset($_SESSION['username']))
{
    header('location:login.php'); //Send them to the login page
}

else
{
    //Your page code here
}
If that sounds terribly complicated try a .htaccess page. They lock out users by requiring authorisation (For .htaccess pages to work you need to be using php with Apache not IIS) the syntax for a .htaccess for can be found at the following URL
http://apache-server.com/tutorials/A...-htaccess.html
Below is an example of a .htaccess file I wrote (paths obscured for obvious reasons)
Code:
AuthUserFile /full-path/to/password/file
AuthName "area name here"
AuthType Basic
require valid-user
You need to make sure that the hosting directory in the httpd.conf file has AllowOverride AuthConfig in it.

You also need to create a .htpasswd file (Make sure it starts with ".ht" as it will be more protected under Apache) in the command line type the following
Code:
htpasswd -bc ./.htpasswd user password
Then for each subsequent user lose the c. The "c" parameter creates the file.

hth

---
David Thorne, Student
UK
 
Old February 26th, 2004, 06:55 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Keep in mind that unless you're running a site on a secure connection (i.e. https://, not http://), all your passwords will be sent as plain text to the server.

Standard HTTP authentication (i.e. using apache's .htaccess files) doesn't really provide any security for anyone who's really interested in gaining access to restricted information.

Using standard HTTP authentication parameters (username, password) and entering a username/password in the "Authorization Required" popup box is the same thing as putting the username/password in the URL to begin with.

More plainly:

  http://<username>:<password>@<url>/



Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
MS Access: Data Access Page sevp95 Access VBA 0 July 14th, 2008 11:07 AM
access C#.Net page as action of calssic ASP page mansharma_s ASP.NET 1.x and 2.0 Application Design 6 January 7th, 2008 10:58 AM
Access Master page control from Content page. angshujit ASP.NET 2.0 Basics 3 January 11th, 2007 06:20 AM
Can't access Tomcat Welcome Page Web Evaluator Apache Tomcat 0 September 1st, 2006 03:20 PM
Data access page access problem :) kev_79 Access 0 September 4th, 2003 04:02 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.