How to Create a secured API using PHP in xml format? -
i have ecommerce website in regularly transactions keeps happening. developing android app same. asked build api using php. api made in xml format. since sending login credentials through scared hack it. can me it.
here way had created xml api using php..
<?php include 'config.php'; include 'database.php'; $sqlcat = "select category_id,image,name table" ; $categories = databasehandler::getall($sqlcat); $xml = new domdocument("1.0","utf-8"); $content = $xml->createelement("content"); $content = $xml->appendchild($content); foreach($categories $category) { $item = $xml->createelement("item"); $catname = $xml->createelement("catname",htmlspecialchars($category['name'])); $catname = $item->appendchild($catname); $catimage = $xml->createelement("catimage",htmlspecialchars($category['image'])); $catimage = $item->appendchild($catimage); $sql = "select image,name,model,price,quantity table; $results = databasehandler::getall($sql); foreach($results $key=>$result) { $product = $xml->createelement("product"); $product->setattribute('id',$key); $model = $xml->createelement("model",$result['model']); $model = $product->appendchild($model); $name = $xml->createelement("name",htmlspecialchars($result['name'])); $name = $product->appendchild($name); $image = $xml->createelement("image",htmlspecialchars($result['image'])); $image = $product->appendchild($image); $price = $xml->createelement("price",$result['price']); $price = $product->appendchild($price); $product = $item->appendchild($product); } $item = $content->appendchild($item); } $xml->formatoutput = true; $output = $xml->savexml(); $xml->save("categories.xml"); ?> and xml in form..
<content> <item> <catname>comp</catname> <catimage/> <product id="0"> <model>156443</model> <name>cd</name> <image>109.jpg</image> <price>48</price> </product> <product id="1"> <model>46876</model> <name>memory card</name> <image>81.jpg</image> <price>12</price> </product> <product id="2"> <model>865793</model> <name>drive</name> <image>51.png</image> <price>2</price> </product> </item> </content> can tell whether way have generated api in xml format correct.
dont make think complex make simple following code
$con = mysql_connect("localhost","root","root") or die("could not connect".mysql_error());
//select database table mysql_select_db("android_maps", $con) or die("could not select database".mysql_error()); //get results mysql query $result = mysql_query("select gmaps.*, urls.* gmaps, urls urls.idgmaps = gmaps.idgmaps") or die(mysql_error()); //run while loop data. while($location = mysql_fetch_array($result)) { $output = '<?xml version="1.0" encoding="utf-8"?>'; $output .= '<data>'; $output .= "<lat>".$location['lat']."</lat>"; $output .= "<long>.".$location['lon']."</long>"; $output .= "<description>.".$location['description']."</description>"; $output .= '</data>'; print $output; } mysql_close($con); }else{ echo "<h1>no results show query</h1>"; } for more info
http://teachingyou.net/php/php-api-development-dreaming-of-your-own-api-make-it-possible-today/
Comments
Post a Comment