...

View Full Version : Can you give the explination of the below code



bhagyaa2ze
03-28-2007, 09:04 AM
Hi,Iam new to PHP.I have code on cookies and sessions,I need explination about these codes.

I need to give expiretime for all the pages.Please can you help me how to give the expire time in all pages using sessions.


login.php
<html>
<head><title>Login</title></head>
<body>

<form action="LoginAction.php" method="Post">
Email Address:<br />
<input type="Text" name="psEmail" />
<br />
Password:<br />
<input type="password" name="psPassword" />
<br />
<input type="submit" value="Login" />

<input type="hidden" name="psRefer" value="<? echo($refer) ?>"
</form>

</body>
</html>


Loginaction.php

<?php

// Check if the information has been filled in
$psEmail = $_REQUEST['psEmail'] ;
$psPassword = $_REQUEST['psPassword'];


if($psEmail == '') {

// No login information
header('Location: http://www.do200m.com/sorry.html');

} else {

// Authenticate user
$hDB = mysql_connect('10.8.6.144', 'my200mdb', 'Bp200mysql');
mysql_select_db('my200mdb', $hDB);

$sQuery = "
Select iUser, MD5(UNIX_TIMESTAMP() + iUser + RAND(UNIX_TIMESTAMP())) sGUID
From tblUsers
Where sEmail = '$psEmail'
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
//set_cookie_fix_domain("session_id", $aResult[1], "3600", '/', 'www.do200m.com', "false", "false");
//setcookie("session_id", $aResult[1]);
$time = mktime()+600;
$date = gmstrftime("%A, %d-%b-%Y %H:%M:%S", (mktime()+6400));


$HTTP_HOST = "www.do200m.com";
//setcookie("session_id", $aResult[1], (time()+6400), "/", "$HTTP_HOST");
setcookie("session_id", $aResult[1], time( )+3600, "/", "", 0);
//header("Set-Cookie: session_id=$aResult[1]; path=/; domain=$HTTP_HOST; expires=".gmstrftime("%A, %d-%b-%Y %H:%M:%S GMT",time()+9600));


header('Location: http://www.do200m.com/suc.php' );
} else {

// Not authenticated

header('Location: http://www.do200m.com/sorry.html' );
}
}
?>

sess.php

<?php
// Initialize a session. This call either creates
// a new session or re-establishes an existing one.
session_start( );

// If this is a new session, then the variable
// $count will not be registered
if (!session_is_registered("count"))
{
session_register("count");
session_register("start");

$count = 0;
$start = time( );
}
else
{
$count++;
}

$sessionId = session_id( );

?>
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.0 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd" >
<html>
<head><title>Sessions</title></head>
<body>
<p>This page points at a session
(<?=$sessionId?>)
<br>count = <?=$count?>.
<br>start = <?=$start?>.
<p>This session has lasted
<?php
$duration = time( ) - $start;
echo "$duration";
?>
seconds.
</body>
</html>

rafiki
03-28-2007, 01:59 PM
try reading the manual its great place to learn about anything PHP related
www.php.net/manual



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum