本人是从事java的,最近在看php,比较感兴趣,就记录下自己最近学习的笔记,比较简单,欢迎大家一起探讨。这次记录的是http请求的简单处理,看下面demo,一共分为4个部分。简述:通过表单请求到处理类,在经过表单跳转的下一个页面。1、首页表单index.html;2、控制类dong.php3、处理数据php-http.php4、最后页面result.html;具体代码如下:
index.html
<span style="font-size:18px;"><html>
<body>
<form action="dong.php" method="post">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="age"><br>
<input type="submit">
</form>
</body>
</html></span>
dong.php
<span style="font-size:18px;"><?php
/**
*php的http请求及处理
*/
require 'php-http.php';
$httpOperation = new HttpOperation();
$httpOperation->start();
?></span>
php-http.php
<span style="font-size:18px;"><?php
/**
*php的http请求及处理
*/
class HttpOperation{
function start()
{
$name = $_POST['name'];
$age = $_POST['age'];
//Redirect('index.php');
$id = $_GET['id'];
header("Location:result.html?name={$name}");
}
}
?></span>
result.html
<span style="font-size:18px;"><html>
<body>
dear <?php echo $_GET['name']; ?>,you are so clever;
</form>
</body>
</html></span>
他人笑我太疯癫,我笑他人看不穿!加油!