[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

11/19/2004 at 10:46PM PST, ID: 21214227
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.0

PHP Login script with MySQL

Asked by techadvanced06 in PHP and Databases

Tags: php, login, mysql, script

Hello,
  I am farely new to PHP and I have stumbled on these set of scripts that work in conjunction to allow a person to login to my website. It works like this: Once you have tried to access the page that is password locked, it redirects you to the incSession.php page which determines if there is a cookie on your computer saying that you are logged in or not, but this page is not seen. If you are not logged in, it directs you to the Login.php page in which you can login. Once you have typed in the User and Password, it directs you to another page that can't be viewed, LoginAction.php. This page determines if you have entered the correct info by connecting to my MySQL page and seeing if that information is there or not. If it is, you will be directed to the page you want to view, if not, you go right back to the Login.php page. What I am trying to do is that I would like to add a timeout to the cookie or the session that the user is on and I would like to have a command here to determine if you have cookies enabled or not, and if not it would show an alert.

Here are the PHP pages in order:

members.php:(ex.)

<?PHP require('incSession.php'); ?>
<html>
..................
</html>

incSession.php:

<?php
// Check for a cookie, if none got to login page
if(!isset($HTTP_COOKIE_VARS['session_id'])) {
header('Location: Login.php?refer='.urlencode($PHP_SELF.'?'.$HTTP_SERVER_VARS['QUERY_STRING']));
}

// Try to find a match in the database
$sGUID = $HTTP_COOKIE_VARS['session_id'];
$hDB = mysql_connect('host', 'user', 'pass');
mysql_select_db('database', $hDB);

$sQuery = "
Select iUser
From tblUsers
Where sGUID = '$sGUID'";

$hResult = mysql_query($sQuery, $hDB);

if(!mysql_num_rows($hResult)) {
// No match for guid
header('Location: Login.php?refer='.urlencode($PHP_SELF.'?'.$HTTP_SERVER_VARS['QUERY_STRING']));
}
?>

Login.php:

<html>
<body>
<p align="center"><form action="LoginAction.php" method="Post">
  <div align="center"><font color="#FF6600"><strong>User:<br />
        <input type="Text" name="psUser" />
        <br />
    Password:</strong></font><br />
    <input type="password" name="psPassword" />
    <br />
    <input type="submit" value="Login" />
   
  <input type="hidden" name="psRefer" value="<? echo($refer) ?>" >
  </div>
</form> </p>
</body>
</html>

LoginAction.php:

<?php
// Check if the information has been filled in
if($psUser == '' || $psPassword == '') {

// No login information
header('Location: Login.php?refer='.urlencode($psRefer));

} else {

// Authenticate user
$hDB = mysql_connect('host', 'user', 'pass');
mysql_select_db('database', $hDB);

$sQuery = "
Select iUser, MD5(UNIX_TIMESTAMP() + iUser + RAND(UNIX_TIMESTAMP())) sGUID
From tblUsers
Where sUser = '$psUser'
And sPassword = password('$psPassword')";

$hResult = mysql_query($sQuery, $hDB);

if(mysql_num_rows($hResult)) {

$aResult = mysql_fetch_row($hResult);

// Update the user record
$sQuery = "
Update tblUsers
Set sGUID = '$aResult[1]'
Where iUser = $aResult[0]";

mysql_query($sQuery, $hDB);

// Set the cookie and redirect
setcookie("session_id", $aResult[1]);

if(!$psRefer) $psRefer = 'index.php';
header('Location: '.$psRefer);

} else {

// Not authenticated
header('Location: Login.php?refer='.urlencode($psRefer));

}
}
?>
[+][-]11/19/04 10:48 PM, ID: 12632352

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/20/04 04:26 AM, ID: 12633359

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP and Databases
Tags: php, login, mysql, script
Sign Up Now!
Solution Provided By: frugle
Participating Experts: 1
Solution Grade: A
 
 
[+][-]11/20/04 08:02 AM, ID: 12634119

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/20/04 08:41 AM, ID: 12634294

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20090824-EE-VQP-74