Home > Backend Development > PHP Problem > How to jump to the page after clicking the button in php

How to jump to the page after clicking the button in php

PHPz
Release: 2023-03-31 09:45:28
Original
5006 people have browsed it

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>
Copy after login

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()">
Copy after login

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;
?>
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template