简体   繁体   中英

Webservices in PHP and Oracle Database

i want to create a web service to check if the login

i create first an html form

  <form action="webservice_ocl.php" method="post">
  <p>Username:
    <input name="user" type="text" />
  </p>
  <p>
    Password:
    <input name="password" type="password" />
  </p>
  <p>
    <input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" />
  </p>
</form>

then i create a php file " webservice_ocl.php to do the traitement

 <?php
session_start();
try {
$dbh = oci_connect('test', '123456', 'localhost/XE');
} catch (PDOException $e)
{
    echo $e->getMessage();
}
if ($_POST['user'] != null and $_POST['user'] != "" and $_POST['password'] != null and $_POST['password'] != "")
{
$username = $_POST['user'];
$password = $_POST['password'];
$sth = oci_parse($dbh ,"SELECT * FROM utilisateur WHERE LOGIN='$username' and PASS='$password'");
oci_execute($sth);
if(oci_fetch($sth)){
       echo "Nice";
    }
    else { echo "nono";}

}

?>

i want to konw , the php file " webservice_ocl.php " is a webservice ??

and how to call them in html using ajax ??

i want to use this on mobile developpement

I wouldn't really class webservice_ocl.php as a webservice as such, a webservice (in my opinion) is usually an SOAP/REST complaint API. See http://en.wikipedia.org/wiki/Web_service .

As for calling this with AJAX, I would personally look into jquery - namely the $.post function, I use this all the time and find it much easier than plain javascript.

Lastly, i would advise you look at how you have wrote your SQL statements - as pointed out by Quentin you are vulnerable for injection, which I have had done before (whoops) and believe me it is not nice!

Hope this helps.

Smithey.

Edit - If your looking at mobile apps, take a look at jquery mobile ;). I'm using it for a project im working on at the minute, its pretty cool!

====== in form.html change type="submit" to type="button" and delete action+mithod attr

<script src="http://code.jquery.com/jquery-latest.min.js" 

type="text/javascript"></script>

 <form id="my-form" >
  <p>Username:
    <input name="user" type="text" />
  </p>
  <p>
    Password:
    <input name="password" type="password" />
  </p>
  <p>
    <input type="submit" name="btnSubmit" id="btnSubmit" value="Submit" />
  </p>
</form>

<div id=result >the result will display here</div>


<script   type="text/javascript">
$("#btnSubmit").click({

  $.post(
    "webservice_ocl.php",
    $("#my-form").serialize(),
    function(data){    $("#result").html(data);  }
  );

});

</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM