Using $_GET variables seems very insecure...
I have created PHP/MYSQL login forms before using only $_POST variables, which is definitely a little more secure, and if this was just a web application I would probably use $_POST variables to authenticate and create a session for the user.
However I would like to start consuming this web service using android and ios devices, in addition to a website interface.
So how do I go about logging a user in securely using only a php webservice?
Although a link to an example or tutorial would be great (I've been searching for days), any advice is greatly appreciated!
<?php
/* require the user as the parameter */
//if(isset($_GET['user']) && intval($_GET['user'])) {
$oneToSearch = $_GET['dude'];
/* soak in the passed variable or set our own */
$format = strtolower($_GET['format']) == 'json' ? 'json' : 'xml'; //xml is the default
/* connect to the db */
$link = mysql_connect('mysql.fake.net','root','pass') or die('Cannot connect to the DB');
mysql_select_db('crlogin',$link) or die('Cannot select the DB');
/* grab the rows from the db */
$query = "SELECT * FROM `users` WHERE `username` LIKE '$oneToSearch'";
$result = mysql_query($query,$link) or die('Errant query: '.$query);
/* create one master array of the records */
$tests = array();
if(mysql_num_rows($result)) {
while($test = mysql_fetch_assoc($result)) {
$tests[] = array('test'=>$test);
}
//}
/* output in necessary format */
if($format == 'json') {
header('Content-type: application/json');
echo json_encode(array('tests'=>$tests));
}
else {
header('Content-type: text/xml');
echo '<tests>';
foreach($tests as $index => $test) {
if(is_array($test)) {
foreach($test as $key => $value) {
echo '<',$key,'>';
if(is_array($value)) {
foreach($value as $tag => $val) {
echo '<',$tag,'>',htmlentities($val),'</',$tag,'>';
}
}
echo '</',$key,'>';
}
}
}
echo '</tests>';
}
/* disconnect from the db */
@mysql_close($link);
}
?>

New Topic/Question
Reply



MultiQuote





|