ckerr27 Posted March 15, 2012 Share Posted March 15, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/258978-help-_please/ Share on other sites More sharing options...
trq Posted March 15, 2012 Share Posted March 15, 2012 Just check if the user is logged in and if not display your message. Quote Link to comment https://forums.phpfreaks.com/topic/258978-help-_please/#findComment-1327598 Share on other sites More sharing options...
Muddy_Funster Posted March 15, 2012 Share Posted March 15, 2012 perhaps you should have paid more attention in class if your looking for specific help you will need to show what you have already and give a clear description of what it is doing V's what you need it to do. Quote Link to comment https://forums.phpfreaks.com/topic/258978-help-_please/#findComment-1327601 Share on other sites More sharing options...
jandrews3 Posted March 16, 2012 Share Posted March 16, 2012 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; Quote Link to comment https://forums.phpfreaks.com/topic/258978-help-_please/#findComment-1328044 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.