在HTML表单解析中发出HTTP请求

时间:2013-06-04 00:39:00

标签: php html forms http openfire

我正在尝试为Openfire XMPP服务器创建注册页面。最简单的路线似乎是使用user service plugin注册帐户,这样可以让用户注册HTTP请求。

基本上,我需要发出像

这样的HTTP请求
http://hostname:9090/plugins/userService/userservice?type=add&secret=passcode&username=kafka&password=drowssap&name=franz&email=franz@kafka.com

将使用密码kafka,名称drowssap等注册用户franz

所以在我看来,最好的方法是创建一个收集用户信息的HTML表单,然后发出HTTP请求。这看起来很简单,但我不确定最佳起点在哪里。 PHP?蟒蛇? wget的?山猫?我不太确定如何在HTML表单中使用它们。

感谢。

1 个答案:

答案 0 :(得分:0)

不要以这种方式包含合理的数据。这是一个GET请求。您需要POST请求(不包括URL中的数据)。

您的HTML应该像:

<form action="saveData.php" method="post">
    <input type="text" name="username" />
    <input type="password" name="password" />
    <!-- other inputs here -->
    <input type="submit" value="Create user" />
</form>

该表单将POST数据发送到saveData.php脚本。该脚本应该处理参数并重定向到另一个页面。

<?php
    // Here process the data the way you want (using data inside $_POST array, i.e. $_POST['username'], $_POST['password'], etc...
    // Usually you'd want to save to a database
   // When done, redirect to "success" page
   header("Location: success.php");
?>

您的success.php页面可以包含任何内容:

<?php
    echo "User created successfully!";
?>