Jump to content

Recommended Posts

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.");

Link to comment
https://forums.phpfreaks.com/topic/237968-help-password-protect-a-webpage/
Share on other sites

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

 

 

 

?>

 

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.

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.