Я только что изучил JQM и получил несколько хороших советов с этого форума. Однако, одна вещь, которая меня озадачивает, это то, нужно ли делать какую-либо специальную разметку для файлов php. Например, у меня есть файл html5, который собирает информацию через форму и использует ajax для обработки формы и отправки в защищенный файл php. по какой-то причине вход в систему запрещается или принимается, но вместо успешного входа в систему вместо secure.php он просто остается на странице html. Это просто учебник, которому я следую, но он дает мне возможность изучить код более подробно и попытаться двигаться дальше. Может кто-нибудь, пожалуйста, помогите с этим? большое спасибо
<!DOCTYPE>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Logistor Login</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="http://code.jquery.com/mobile/latest/jquery.mobile.min.css" rel="stylesheet" type="text/css"/>
<script src="http://code.jquery.com/jquery-1.6.2.min.js" type="text/javascript"></script>
<script src="http://code.jquery.com/mobile/latest/jquery.mobile.min.js" type="text/javascript"></script>
<script>
$(function()
{
$("#login_form").submit(function()
{
//remove all the class add the messagebox classes and start fading
$("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
//check the username exists or not from ajax
$.post("ajax_login.php",{ user_name:$('#username').val(),password:$('#password').val(),rand:Math.random() } ,function(data)
{
if(data=='yes') //if correct login detail
{
$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html('Logging in.....').addClass('messageboxok').fadeTo(900,1,
function()
{
//redirect to secure page
document.location='secure.php';
});
});
}
else
{
$("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
{
//add message and change the class of the box and start fading
$(this).html('Please provide the correct credentials').addClass('messageboxerror').fadeTo(900,1);
});
}
});
return false; //not to post the form physically
});
//now call the ajax also focus move from
$("#password").blur(function()
{
$("#login_form").trigger('submit');
});
});
</script>
</head>
<div data-role="page" id="login" data-title="Logistor Login" data-theme="b">
<div data-role="header">
<h1>Logistor Login</h1>
</div>
<div data-role="content">
<form method="post" id="login_form" action="">
<div data-role="fieldcontain">
<label for="username">Username *</label>
<input type="text" name="username" id="username" value="" size="66" />
<div id="userError">
</div>
</div>
<div data-role="fieldcontain">
<label for="password">Password *</label>
<input type="password" name="password" id="password" value="" size="46" />
<div id="passError">
</div>
</div>
<div id="login_message"></div>
<div id="submitDiv" data-role="fieldcontain">
<input name="Submit" type="submit" id="submit" value="Login" data-inline="true" />
<span id="msgbox" style="display:none"></span>
</div>
</form>
</div>
<div data-role="footer"">
<h4>Logistor 2009-2011</h4>
</div>
</div>
</form>
secure.php
<?php session_start();
// if session is not set redirect the user
if(empty($_SESSION['u_name']))
header("Location:index.html");
//if logout then destroy the session and redirect the user
if(isset($_GET['logout']))
{
session_destroy();
header("Location:index.html");
}
echo "<a href='secure.php?logout'><b>Logout<b></a>";
echo "<div align='center'>You Are inside secured Page</a>";
?>
Ajax-login.php
<?php session_start();
//Connect to database from here
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//select the database | Change the name of database from here
mysql_select_db('test');
//get the posted values
$user_name=htmlspecialchars($_POST['user_name'],ENT_QUOTES);
$pass=md5($_POST['password']);
//now validating the username and password
$sql="SELECT username_usr, password_usr FROM user_usr WHERE username_usr='".$user_name."'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
//if username exists
if(mysql_num_rows($result)>0)
{
//compare the password
if(strcmp($row['password_usr'],$pass)==0)
{
echo "yes";
//now set the session from here if needed
$_SESSION['u_name']=$user_name;
}
else
echo "no";
}
else
echo "no"; //Invalid Login
?>