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
https://forums.phpfreaks.com/topic/258978-help-_please/
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
https://forums.phpfreaks.com/topic/258978-help-_please/#findComment-1328044
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.