Jump to content

Recommended Posts

hi im trying to get the sessions working for my login page
the code doesnt give me any error messages but it doesnt seem to restrict any access either
this is wot i have so far:

session_start();
if($_POST){
$_SESSION['user_name']=$_POST["user_name"];
$_SESSION['password']=$_POST["password"];
}

$query = ("select * from customers
where user_name='" . $_SESSION['user_name'] . "' and password='" . $_SESSION['password'] . "'");

$result = @mysql_query($query, $connection) or die(mysql_error());
$row = mysql_fetch_array($result, MYSQL_ASSOC);

if ($_SESSION['user_name'] == $row['user_name'] AND $_SESSION['password'] == $row['password']){

this then leads to the either successful or unsuccessful login page
hope somebody can help
Link to comment
https://forums.phpfreaks.com/topic/7721-php-session-help/
Share on other sites

What you need to do, is use the POST[username] and POST[password] variables in your query to the database. If the database finds a result for that username and password combination, THEN set the session variable with the username.

[code]
session_start();

$query = "SELECT * FROM users WHERE username='$_POST[username]' AND password='$_POST[password]'";
$result = mysql_query($query);

if($result=="1") { $_SESSION[username]=$_POST[username]; echo "Hello $_SESSION[username], you're logged in"; }
else { echo "Thou art imposter!"; }

[/code]

Once the session variable is set, you can then use that as your security measure... each page that you want protected should have something like this

[code]

<?php session_start();

if(!isset($_SESSION[username])) { echo "go away"; } else {

// Your content here.

}
?>
[/code]

Send me a PM if you want any further help & I'll send you the code for the login procedure i use.
Link to comment
https://forums.phpfreaks.com/topic/7721-php-session-help/#findComment-28170
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.