php 實現頁面跳轉

在php中我們可以使用header方法來實現頁面的跳轉,如:

$url = 'http://www.wj0511.com';
header("Location: " . $url);
exit();

使用header方法可以實現頁面跳轉,但是隻支持get跳轉,當我們需要實現post跳轉的話,使用header方法就無法實現了,這時候我們可以在php中執行js跳轉來實現post跳轉,如:

$url = 'http://www.wj0511.com';
echo <<<EOT
<form name='test' action='{$url}' method='POST'>
</form>
<script type='text/javascript'>
    document.test.submit();
</script>
EOT;
exit;

如上我們就可以實現post跳轉功能了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章