PHP会话变量未成功传递

时间:2015-02-05 14:29:52

标签: php session-variables

我第一次尝试使用PHP进行会话。例如,我希望创建一个名为phonemessearch2.php的页面的链接,该页面加载该页面并将变量phon1设置为" M",phon3到" L",phon4到& #34; IY&#34 ;. amd umatch to" umatch"。因此,我链接到此URL:

phonemessearch2.php phon1 = M&安培; phon3 = L&安培; phon4 = IY&安培; umatch = umatch

以下是目标网页中的代码:

session_set_cookie_params(3600,"/");
session_start();

//submitted form variable definitions

if(isset($_POST['umatch']))
{
    $umatch = $_POST['umatch'];
} else {
    if( !isset($_SESSION['umatch']) )
    {
        $umatch = '';
    } else {
        $umatch = $_SESSION['umatch'];
    }
} 
$_SESSION['umatch'] = $umatch;


if(isset($_POST['phon1']))
{
    $phon1 = $_POST['phon1'];
} else {
    if( !isset($_SESSION['phon1']) )
    {
        $phon1 = '';
    } else {
        $phon1 = $_SESSION['phon1'];
    }
} 
$_SESSION['phon1'] = $phon1;

if(isset($_POST['phon2']))
{
    $phon2 = $_POST['phon2'];
} else {
    if( !isset($_SESSION['phon2']) )
    {
        $phon2 = '';
    } else {
        $phon2 = $_SESSION['phon2'];
    }
} 
$_SESSION['phon2'] = $phon2;

if(isset($_POST['phon3']))
{
    $phon3 = $_POST['phon3'];
} else {
    if( !isset($_SESSION['phon3']) )
    {
        $phon3 = '';
    } else {
        $phon3 = $_SESSION['phon3'];
    }
} 
$_SESSION['phon3'] = $phon3;

if(isset($_POST['phon4']))
{
    $phon4 = $_POST['phon4'];
} else {
    if( !isset($_SESSION['phon4']) )
    {
        $phon4 = '';
    } else {
        $phon4 = $_SESSION['phon4'];
    }
} 
$_SESSION['phon4'] = $phon4;

if(isset($_POST['phon5']))
{
    $phon5 = $_POST['phon5'];
} else {
    if( !isset($_SESSION['phon5']) )
    {
        $phon5 = '';
    } else {
        $phon5 = $_SESSION['phon5'];
    }
} 

页面加载时,它不会合并URL中的变量值。所有变量都是空白的。我怎么能让他们坚持下去?

谢谢!

1 个答案:

答案 0 :(得分:5)

我认为这与您的会话无关 - 像phonemessearch2.php?phon1=M&phon3=L&phon4=IY&umatch=umatch这样的网址中的变量位于$_GET,而不是$_POST