to be honest ive no idea, probobly just the way i made it, heres the new and updated script:
also what i found was even tho the user logged in correctly you have to refresh the browser to make the changes work. (probobly the same reason why this forum and others go to a redirect/refresh page in-between changes)
login.php
<?php
session_start();
if (isset($_POST['user_name'])) {
//be sure you check the values of post against a permitted list of characters (ie., alphanumeric + some punctuation) before you do this:
extract($_POST);
$result = mysql_query(" SELECT username, password FROM ".$membertable." WHERE username = '".$user_name."'");
//query the database here with "SELECT username. password FROM members WHERE username=$user_name"
// if result = mysql error, username and password entered are incorrect
if (!$result) {
//they have supplied an invalid username/password pair!
print '<p>Supplied username-password combination is invalid. Please try again.</p>';
loginForm();
exit();
}
else {
//they checked out. register their username and password
session_register('user_name', 'pass_word');
//now show them the stuff.
print "Woohoo! You have successfully logged in as: $user_name<br />";
print '<a href="index.php">Click here</a> to complete the login procedure';
logoutButton();
}
}
elseif (session_is_registered('user_name') && session_is_registered('pass_word')) {
//they didn't supply a username and password, but they are registered with the session
//check to see if they want to log out
if ($task == 'logout') {
session_unset();
session_destroy();
loginForm();
}
//otherwise give them the goods
else {
print "You're still logged in as $user_name<br />";
logoutButton();
}
}
else {
//if they get here, it is probably the first time they're visiting the page
//give them the login form
loginForm();
}
function loginForm() {
//print out a login form - in a function like this, you don't have to write it out a billion times
print "Login Here:<br>
<form method='post' action='login.php'>
Username <input type='text' name='user_name'><br>
Password <input type='password' name='pass_word'><br>
<input type='submit' name='submit' value='Login!'>";
}
function logoutButton() {
//print out the logout button
print '<form action="login.php" method="post">
<input type="hidden" name="task" value="logout" />
<input type="submit" value="Logout" />
</form>';
}
?>
and here is the script to check whether the user is logged in for the rest of the site.
at the top of ismember.php is an if statement that checks whether the session has already started, but i dont have the code yet for that if it is at all possible...
also my site uses a header.php so i have session_start() at the top of that so i dont have session_start() in the login page like above.
ismember.php
<?
if (session has started) {}
else {session_start();}
require ("".$DOCUMENT_ROOT."/cgi-bin/connect.php");
$username = $_SESSION['user_name'];
$password = $_SESSION['pass_word'];
$result = mysql_query("SELECT username, password FROM ".$membertable." WHERE username = '".$username."' AND password = '".$password."' ";
if (!$result) {$flag=0} // if flag = 0 user not logged on
else {$flag=1} // if flag = 1 user is logged on...
/*
To incorporate this into your code.
simply insert this into the top of your pages:
require("ismember.php");
and then in your code add this to enable it:
if ($flag==0) {
echo "You do not have access to this page!";
elseif ($flag==1) {
echo "You have access to this page";}
*/
?>
hope this helps, its not the best solution but it is the one im willing to use, also if any of you have any comments for security issues with this please post..
============EDIT=================
ive just found out that there is no thang to check whether i session has already been started, so im not sure on what to do. if anyone can help please do 😃
========NEW EDIT===========
right for that if statement just do a check to see if a session variable is there and if so dont start session then else start session
if ($_SESSION['user_name']) {}
else {session_start();}