In PHP, there are many ways to jump to a specified page after clicking a button. 3 common methods will be introduced below.
Method 1: Using the form in HTML
You can use the submit button in the HTML form. The code is as follows:
<form action="跳转的页面URL" method="get"> <input type="submit" value="点击跳转"> </form>
Replace the "jumped page URL" with Just the address of the page you want to jump to.
When the user clicks the submit button, the browser will submit the form to the specified URL to realize page jump.
Method 2: Use JavaScript to implement page jump
You can use the location.href attribute in JavaScript to implement page jump. The code is as follows:
<script> function jumpToPage() { location.href = "跳转的页面URL"; } </script> <input type="button" value="点击跳转" onclick="jumpToPage()">
Replace "Jump" Just replace "Page URL" with the address of the page you want to jump to.
When the user clicks the button, the jumpToPage() function is called to realize the page jump.
Method three: Use PHP to implement page jump
You can use PHP's header() function to implement page jump. The code is as follows:
<?php header("Location: 跳转的页面URL"); exit; ?>
Change the "jumped page" Just replace "URL" with the address of the page you want to jump to.
Note that no content can be output before using the header() function to jump to the page, otherwise the jump will fail. Therefore, you must use the exit or die function to end the output of the current page before jumping.
To sum up, the above three methods can all achieve page jump. Which method to use can be chosen according to your own needs and specific circumstances.
The above is the detailed content of How to jump to the page after clicking the button in php. For more information, please follow other related articles on the PHP Chinese website!