[英]How to deal with multiple request_method?
My PHP page can receive the same data from two differents pages, the first one send it using GET, and the second with sessions. 我的PHP页面可以从两个不同的页面接收相同的数据,第一个使用GET发送,而第二个带有会话。 How can I make this thing work ?
我怎样才能使这件事起作用?
//$var = empty;
//$_GET['id'] = empty;
//User come from page1.php
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$var = $_GET['data'];
}
else {
//User come from page2.php
$var = $_SESSION['data'];
}
Try this: 尝试这个:
if (array_key_exists('data', $_GET)) {
$var = $_GET['data'];
} else {
$var = $_SESSION['data'];
}
If you have two pages, page1.php
and page2.php
and you want to know at first hand which page it is, and what is the ?data=
value... then this will do the trick. 如果您有两个页面,分别是
page1.php
和page2.php
并且您想直接了解它是哪一页,以及什么是?data=
value ...,那么就可以解决问题。
<?php
$data = (isset($_GET['data']) && !empty($_GET['data'])) ? $_GET['data'] : '';
if($_SERVER['SCRIPT_NAME'] === 'page1.php'){
$var = $data;
}else if($_SERVER['SCRIPT_NAME'] === 'page2.php'){
$var = $_SESSION['data'];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.