Hi,
I dont know if this is the right place to ask this question. But as time is limited and here I have always got the right answers I am asking it away.
I want to setup a login page on a local server so as to communicate with it via android. As time permits, I googled and found out the necessary php script and mySQL code needed for the same. I don't know where to add these code in the local server and connect them. :( (This is mainly for testing purpose as we would develop a website in Django latter on.) Any help would be much appreciated..
<?php
unset($_GET);
if( isset($_POST['username']) && isset($_POST['password']) ) {
echo '<?xml version="1.0"?>'."\n";
echo "<login>\n";
if (!@mysql_connect('host', 'user', 'pass')) { error(1); }
if (!mysql_select_db('database')) { error(2); }
if(get_magic_quotes_gpc()) {
$login = stripslashes($_POST['username']);
$pass = stripslashes($_POST['password']);
} else {
$login = $_POST['username'];
$pass = $_POST['password'];
}
unset($_POST);
$kid = login($login, $pass);
if($kid == -1) {
error(3);
} else {
printf(' <user id="%d"/>'."\n",$kid);
}
echo "</login>";
}
function error($ec) {
printf(' <error value="%d"/>'."\n".'</login>',$ec);
die();
}
function login($login, $pass) {
$select = "SELECT user_id FROM auth_table ";
$where = "WHERE username = '%s' AND password = '%s'";
$fixedlogin = mysql_real_escape_string($login);
$fixedpass = mysql_real_escape_string($pass);
$query = sprintf($select.$where, $fixedlogin, $fixedpass);
$result = mysql_query($query);
if(mysql_num_rows($result) != 1) { return -1; }
$row = mysql_fetch_row($result);
return $row[0];
}
?>