其他教程

其他教程

Products

当前位置:首页 > 其他教程 >

http请求类型 GET请求

GG网络技术分享 2025-03-18 16:17 0


请求参数以键值对的方式,附加到url地址上,称为查询字符串,用?号与当前脚本分隔

url格式: index.php?name=探乎&age=30

受url长度限制, GET方式传递的数据也是有限制的

服务器端脚本使用预定义变量数组 $_GET 进行接收

index.php?name=探乎&age=18&sex=2

【PS】 ?后面都是参数,多个参数用&连接分开,每个参数格式例子 name=鹏仔

<?php

print_r($_GET);

?>

输出结果

Array ( [name] => 探乎 [age] => 18 [sex] => 2 )

<?php

echo $_GET[\'name\'] . \'<br>\';

echo $_GET[\'sex\'];

?>

输出结果

探乎

2

<!DOCTYPE html>

<html lang=\"en\">

<head>

<meta charset=\"UTF-8\">

<title>GET</title>

</head>

<body>

<form action=\"\" method=\"get\">

<input type=\"email\" name=\"email\" value=\"\" placeholder=\"请输入邮箱\">

<input type=\"password\" name=\"password\" value=\"\" placeholder=\"请输入密码\">

<button>登录</button>

</form>

</body>

</html>

<?php

// 判断是否存在 $_GET[\'email\'] ,存在则输出

if( isset($_GET[\'email\']) ){

echo \'邮箱:\' . $_GET[\'email\'];

}

echo \'<br>\';

// 判断是否存在 $_GET[\'password\'] ,存在则输出

if( isset($_GET[\'password\']) ){

echo \'密码:\' . $_GET[\'password\'];

}

?>

输出结果

邮箱:921349888@qq.com

密码:123456

扩展:三元运算符 ? :

? 前面是条件,跟if的括号 () 效果一样

? 后面 :前面,跟if {}里面效果一样

:后面跟 else {}里面的效果一样

PHP

<!DOCTYPE html>

<html lang=\"en\">

<head>

<meta charset=\"UTF-8\">

<title>GET</title>

</head>

<body>

<form action=\"\" method=\"get\">

<input type=\"email\" name=\"email\" value=\"\" placeholder=\"请输入邮箱\">

<input type=\"password\" name=\"password\" value=\"\" placeholder=\"请输入密码\">

<button>登录</button>

</form>

</body>

</html>

<?php

echo isset($_GET[\'email\']) ? \'邮箱:\' . $_GET[\'email\'] : \'\';

echo \'<br>\';

echo isset($_GET[\'password\']) ? \'密码:\' . $_GET[\'password\'] : \'\';

?>

用户将输出的值,回显至表单

PHP

<!DOCTYPE html>

<html lang=\"en\">

<head>

<meta charset=\"UTF-8\">

<title>GET</title>

</head>

<body>

<form action=\"\" method=\"get\">

<!-- 将用户输入的内容动态添加到value字段中, 创建具有粘性的表单 -->

<input type=\"email\" name=\"email\" value=\"

<?php

echo isset($_GET[\'email\']) ? $_GET[\'email\'] : \'\';

?>

\" placeholder=\"请输入邮箱\">

<input type=\"password\" name=\"password\" value=\"

<?php

echo isset($_GET[\'password\']) ? $_GET[\'password\'] : \'\';

?>

\" placeholder=\"请输入密码\">

<button>登录</button>

</form>

</body>

</html>

<?php

echo isset($_GET[\'email\']) ? \'邮箱:\' . $_GET[\'email\'] : \'\';

echo \'<br>\';

echo isset($_GET[\'password\']) ? \'密码:\' . $_GET[\'password\'] : \'\';

?>本文章最后由 admin 于 2024-02-27 18:10 编辑

标签: 请输入 邮箱

提交需求或反馈

Demand feedback