<?php
session_start();
$request = isset($_GET['request']) ? $_GET['request'] : '';
if ($request == 'xml') {
header('Content-Type: text/xml');
$xml = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' . "\n";
$forgotpassword = isset($_GET['forgotpassword']) ? $_GET['forgotpassword'] : '';
if ($forgotpassword == 'Y') {
$username = isset($_GET['loginu']) ? $_GET['loginu'] : '';
if ($username == '') {
$xml .= "<root>Error: Please enter your email address or username in the username field</root>\n";
echo $xml;
exit;
}
// If the account does not exist, no reason to email, but report back to the webpage as if it did exist.
if ($username == 'test') {
// Do something here, like email the admin or the user directly.
}
$xml .= "<root>The site administrator has been notified and will contact you with your new password shortly</root>\n";
echo $xml;
exit;
}
$authenticated = isset($_SESSION['example_username']) ? 1 : 0;
if ($authenticated) {
$xml .= "<root>You are logged in as " . $_SESSION['example_username'] . "</root>\n";
echo $xml;
exit;
}
$show_first_time = isset($_SESSION['example_show_first_time']) ? $_SESSION['example_show_first_time'] : 0;
$username = isset($_GET['loginu']) ? $_GET['loginu'] : '';
$password = isset($_GET['loginp']) ? $_GET['loginp'] : '';
if ($username == '' && $password == '') {
if ($show_first_time) {
$xml .= "<root>Since this is your first time logging in, please choose the username you would like to use and a new password</root>\n";
} else {
$xml .= "<root>Please enter username and password to login</root>\n";
}
echo $xml;
exit;
}
if ($username == '' || $password == '') {
$xml .= "<root>Error: Missing username or password</root>\n";
echo $xml;
exit;
}
if ($show_first_time == 0) {
// Simulate a database lookup here.
$user_id = ($username == 'test' && $password == 'test');
if (isset($user_id) && $user_id != 0) {
$is_first_time = 1;
if ($is_first_time) {
$_SESSION['example_show_first_time'] = 1;
$xml .= "<root>Since this is your first time logging in, please choose the username you would like to use and a new password</root>\n";
} else {
$_SESSION['example_username'] = $username;
$xml .= "<root>Success logging in as " . $_SESSION['example_username'] . "</root>\n";
}
} else {
sleep(3);
$xml .= "<root>Error: User not found in system or password is incorrect</root>\n";
}
} else {
// Simulate storing the new username and password.
$_SESSION['example_username'] = $username;
$xml .= "<root>Success logging in as " . $_SESSION['example_username'] . "</root>\n";
}
echo $xml;
exit;
}
if ($request == "reset") {
session_start();
unset($_SESSION['example_username']);
unset($_SESSION['example_show_first_time']);
header("Location: example.php");
exit;
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Example Login</title>
<script type="text/javascript" src="../common/jax-xmlhttprequest.js"></script>
<script type="text/javascript" src="jax-login.js"></script>
<style type="text/css">
label.jax_login {
display: block;
position: absolute;
}
input.jax_login {
margin-left: 110px;
}
a.jax_login {
font-size: 10px;
margin-left: 15px;
}
</style>
</head>
<body onLoad="jaxLoginRegister('example.php?request=xml', 'example');">
<h3 id="h3_title">Example Login</h3>
<div class="example_indent">
<div id="example"></div>
</div>
<a href="example.php?request=reset">Reset session info</a><br />
</body>
</html>