PHP和Oracle数据库中的Webservices
我想创建一个web服务来检查登录 我首先创建一个html表单PHP和Oracle数据库中的Webservices,php,jquery,ajax,web-services,web,Php,Jquery,Ajax,Web Services,Web,我想创建一个web服务来检查登录 我首先创建一个html表单 <form action="webservice_ocl.php" method="post"> <p>Username: <input name="user" type="text" /> </p> <p> Password: <input name="password" type="password" /> <
<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>
用户名:
密码:
然后我创建了一个php文件“webservice_ocl.php”来进行测试
<?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";}
}
?>
我不会将webservice\u ocl.php真正归类为webservice,因为webservice(在我看来)通常是SOAP/REST投诉API。请参阅
至于用AJAX调用它,我个人会研究jquery——即$.post函数,我一直在使用它,发现它比普通javascript容易得多
最后,我建议您看看您是如何编写SQL语句的——正如Quentin所指出的,您很容易受到注射的攻击,我以前也做过(哎呀),相信我,这不好
希望这有帮助
史密斯
编辑-如果你在看移动应用程序,看看jquery mobile;)。我正在用它做一个我正在做的项目,它很酷!=======in form.html将type=“submit”改为type=“button”并删除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>
用户名:
密码:
结果将显示在这里
$(“#btnsupmit”)。单击({
美元邮政(
“webservice_ocl.php”,
$(“#我的表单”).serialize(),
函数(数据){$(“#结果”).html(数据);}
);
});
你对MeDange:你的问题还不清楚,你对你自己的需求是很脆弱的。有很多关于如何做AJAX的教程,想知道一个。我想知道“WebService Enph.Oph.php”是否被认为是一个Web服务??WebService eOC.php= Web Service??是的,我想在PosiGAP上使用它来构建一个移动AppsMy P。问题是:我有一个在php和oracle db上创建的网站,我想通过使用phonegap和web服务为它创建一个移动应用程序,所以你能帮助我如何为这个应用程序创建一个web服务吗?我从来没有使用过web服务你好,我可以给你一些有用的建议。我建议你使用rest而不是soap,因为我个人发现soap more很复杂(我相信很多人会不同意!)。首先,我会有一个很好的通读。接下来,你可以看看哪一个将解释如何在PHP中创建rest服务,以及一些代码示例等。希望这有帮助,很好的外观!谢谢,如果a想创建我的个人web服务,是否可以不使用rest或soap???