从 url 获取变量
我是 php 新手,但我正在尝试。我需要你们的帮助。 我在浏览器地址栏中有以下网址 www.dome.com\mypage.php?stu=12234342 我正在尝试将 url 从主页传递到选择案例页面调用 select.php 如果我应该回显该网址,我会得到 www.dome.com\select.php。所以我决定回显 $_SERVER['HTTP_REFERER'] 相反,这给了我正确的网址。我如何回显 www.dome.com\mypage.php?stu=12234342 (12234342) 中的变量 到 select.php。 select.php 包含需要 $var Stu=12234342 才能显示正确消息的代码。
$request_url=$_SERVER['HTTP_REFERER'] ; // 从浏览器获取 url 回显 $request_url;
$cOption = $_GET['id'];
switch($cOption) {
case 1:
echo ' some text';
break;
case 2:
echo ' this page.php';
break;
case 3:
echo 'got it';
break;
default:
echo 'Whoops, didn\'t understand that option: <i>'.$cOption.'</i>';
}
?>
i am new to php, but im trying. i need you guys help.
i have the following url in the browser address bar www.dome.com\mypage.php?stu=12234342
i am trying to pass the url from the main page to the select case page call select.php
if i should echo the url i get www.dome.com\select.php. so i have decided to echo $_SERVER['HTTP_REFERER']
instead, this gives me the correct url. how can i echo the variable from www.dome.com\mypage.php?stu=12234342 (12234342)
unto select.php. select.php contains code that needs the $var stu=12234342 in order to display the correct message.
$request_url=$_SERVER['HTTP_REFERER'] ; // takes the url from the browers
echo $request_url;
$cOption = $_GET['id'];
switch($cOption) {
case 1:
echo ' some text';
break;
case 2:
echo ' this page.php';
break;
case 3:
echo 'got it';
break;
default:
echo 'Whoops, didn\'t understand that option: <i>'.$cOption.'</i>';
}
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 parse_url() 和 parse_string() 从 url 中获取变量:
但请注意:您不能依赖 HTTP_REFERER 的可用性。
You may use parse_url() and parse_string() to grab the variable from a url:
But note: you can't rely on the availability of HTTP_REFERER.
尝试
select.php
try
on select.php
这就是为什么您需要像这样调用 select.php 文件:
www.dome.com/select.php?stu=12234342
然后你可以添加:
顺便说一句,你需要研究一下 XSS,因为这是一个巨大的漏洞。
That's why you need to call the select.php file like this:
www.dome.com/select.php?stu=12234342
and then you can add:
By the way, you need to research about XSS, because that's a huge vulnerability.