给我写一个简单的php网页跳转代码
时间: 2024-05-08 19:19:23 浏览: 17
好的,以下是一个简单的 PHP 网页跳转代码:
```
<?php
header("Location: https://www.example.com");
exit;
?>
```
这个代码会将当前页面重定向到指定的网址(这里以 https://www.example.com 为例)。
相关问题
用php写一个生成页面跳转的js
可以使用以下代码来生成一个页面跳转的JS:
```php
<?php
header("refresh:2;url=http://www.example.com");
?>
<html>
<head>
<meta http-equiv="refresh" content="2;url=http://www.example.com">
<script>
setTimeout(function(){
window.location.href = "http://www.example.com";
}, 2000);
</script>
</head>
<body>
页面将在2秒后跳转到:http://www.example.com
</body>
</html>
```
其中,第一种方式使用了PHP的头部重定向,会直接跳转到指定的URL;第二种方式使用了JS的setTimeout函数,会在指定时间后跳转页面。您可以根据需要选择其中的一种方式。
写一个登录页面的php代码
<?php
// 如果用户已经登录,则直接跳转到主页
session_start();
if (isset($_SESSION['username'])) {
header("Location: index.php");
exit();
}
// 处理表单提交请求
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// 获取表单提交数据
$username = $_POST["username"];
$password = $_POST["password"];
// TODO: 根据$username和$password查询数据库,判断用户是否存在
// 用户存在,则保存用户信息到session中,并跳转到主页
$_SESSION['username'] = $username;
header("Location: index.php");
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>登录页面</title>
</head>
<body>
<h1>登录页面</h1>
<form method="post">
<label for="username">用户名:</label>
<input type="text" name="username" id="username" required><br><br>
<label for="password">密码:</label>
<input type="password" name="password" id="password" required><br><br>
<button type="submit">登录</button>
</form>
</body>
</html>
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)