本人是從事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>
他人笑我太瘋癲,我笑他人看不穿!加油!