bremen1984 Posted May 31, 2011 Share Posted May 31, 2011 hi all i have a code that i am trying to password to protect my webpage and i cant seen to get it to coonect to mysql DB. here is the code $c_username = "root"; $c_password = "Steph1989"; $c_host = "localhost"; $c_database = "eclipse_media"; // Connect. $connection = mysql_connect($c_host, $c_username, $c_password) or die ("It seems this site's database isn't responding."); mysql_select_db($c_database) or die ("It seems this site's database isn't responding."); Quote Link to comment https://forums.phpfreaks.com/topic/237968-help-password-protect-a-webpage/ Share on other sites More sharing options...
Kieran Menor Posted May 31, 2011 Share Posted May 31, 2011 What error messages do you get? Did you actually enable root logins for your database? Quote Link to comment https://forums.phpfreaks.com/topic/237968-help-password-protect-a-webpage/#findComment-1222763 Share on other sites More sharing options...
bremen1984 Posted May 31, 2011 Author Share Posted May 31, 2011 there are no errors, it just takes me back to the login page, i have fix it and here is the new code. i can get it to ask for the login info but after they have loged in it will ask for the login every time the push the link is there a way that i can have it ask once and then after they log out or close the browser, it will ask again? here is the code. <?php session_start(); // Check if user is logged-in. if(isset($_SESSION['username'])){ // User is logged in $link_to = $_SESSION['username']."_page.php"; } else{ // User is not logged-in, so send them away. header ("location: login.php"); } // The rest of your page here ... ?> Quote Link to comment https://forums.phpfreaks.com/topic/237968-help-password-protect-a-webpage/#findComment-1222803 Share on other sites More sharing options...
HDFilmMaker2112 Posted May 31, 2011 Share Posted May 31, 2011 Did you actually set your session for $_SESSION['username']; Should be something like this, on the page the log-in form is submitted to: $_SESSION['username']=$_POST['username']; Then you can create a log-out page: session_start(); session_unset(); session_destroy(); header("Location: /path/to/page/you/want/to/send/your/user/after/log-out"); Save that as logout.php and link to it, when somebody clicks the link it will unset $_SESSION['username']; and require typing in the log-in information again. Quote Link to comment https://forums.phpfreaks.com/topic/237968-help-password-protect-a-webpage/#findComment-1222814 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.