Home  >  Article  >  Backend Development  >  Simple and easy to understand PHP code: jump to the specified page

Simple and easy to understand PHP code: jump to the specified page

王林
王林Original
2024-03-07 16:39:04889browse

Simple and easy to understand PHP code: jump to the specified page

In PHP, it is very simple to implement page jump. You can use the header() function to achieve it. The following is a simple sample code:

<?php
// 要跳转的页面地址
$redirect_url = 'https://www.example.com';

// 使用header函数实现跳转
header('Location: ' . $redirect_url);
exit;
?>

In the above code, the page address to be jumped to is first defined, and then the page jump is implemented through header('Location: ' . $redirect_url);. When using the header function, you need to make sure that no HTML content is output in the code, because the header function must be called before the page outputs any content. Finally, use exit; to ensure that subsequent code will not be executed.

This code is very simple and intuitive, suitable for implementing a simple page jump function.

The above is the detailed content of Simple and easy to understand PHP code: jump to the specified page. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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