Jump to content

HELP!!!! _Please


ckerr27

Recommended Posts

hi everybody,

 

i am doing my university project, i need to create a login feature on my website and i am using php. can anybody tell me some html or php code to display a message "login required", when a button on the home page is pressed. e.g. if the member is not logged in and presses the guestbook link button I want this error code to appear,

 

thanks

 

connor

Link to comment
Share on other sites

This is a common type of login feature. I use it myself. Put a button on your homepage linking to a members only page. On the members only page (and on all such pages on your website) use the following:

 

session_start();

if (!isset($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])
    || !($_SERVER['PHP_AUTH_USER'] == $uname && $_SERVER['PHP_AUTH_PW'] == $pword))
{
    header('WWW-Authenticate: Basic realm="Authorization Required!"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'Authorization Required!';
    exit;
}
else
{
your page coding goes here
}

 

When clicked, the button will take you to the linked page but will NOT reveal any of it until you have entered a username and password. I use $uname and $pword as variables checked against a database specific to an individual member. BUT, you could just have one set username and password for anybody. If this is a school project, that would certainly be easier. If you go this route, just insert something like:

 

uname = bob;
password = dallascowboys;

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.