0

My PHP page can receive the same data from two differents pages, the first one send it using GET, and the second with sessions. 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'];

}
4

2 回答 2

1

尝试这个:

if (array_key_exists('data', $_GET)) {
    $var = $_GET['data'];
} else {
    $var = $_SESSION['data'];
}
于 2013-07-08T21:49:44.003 回答
0

如果您有两页,page1.php并且page2.php您想直接知道它是哪一页,以及?data=价值是什么……那么这将解决问题。

<?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'];

}
于 2013-07-08T22:01:14.220 回答