网站代码
<?php
include('config.php');
$link =mysql_connect($db_host,$username,$password);
mysql_select_db($db_name);
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$sql="SELECT * FROM logintbl WHERE stu_email='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_start();
$_SESSION['username'] = $myusername;
$_SESSION['password'] = $mypassword;
header("location:login_success.php");
}
else {
header('Location: http://www.xxxxxxx.com/pabrowser/index.php?succmsg1=INVALID.RETRY');
}
?>
代码更改为与Android设备一起使用
<?php
$link = mysql_connect(xxxxxxxx);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("brainoidultrafb", $link);
$sql="SELECT * FROM logintbl WHERE stu_email='".$_REQUEST['id']."' and password='".$_REQUEST['pass']."'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
$output[]=$count;
print(json_encode($output));
mysql_close();
?>
输出应该是0或1,这将允许设备登录。