PHP session 变量没有通过成功
PHP session variables not passing successfully
我将在 PHP 中首次涉足会议。例如,我想为一个名为 phonemessearch2.php 的页面创建一个 link 来加载该页面并将变量 phon1 设置为 "M",phon3 为 "L",phon4 为 "IY"。 amd 匹配 "umatch"。因此我 link 到这个 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 的变量值。所有的变量都是空白的。我怎样才能让它们坚持下去?
谢谢!
我认为这与您的会话没有任何关系 - URL 中的变量(如 phonemessearch2.php?phon1=M&phon3=L&phon4=IY&umatch=umatch
)将在 $_GET
中,而不是 $_POST
中。
我将在 PHP 中首次涉足会议。例如,我想为一个名为 phonemessearch2.php 的页面创建一个 link 来加载该页面并将变量 phon1 设置为 "M",phon3 为 "L",phon4 为 "IY"。 amd 匹配 "umatch"。因此我 link 到这个 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 的变量值。所有的变量都是空白的。我怎样才能让它们坚持下去?
谢谢!
我认为这与您的会话没有任何关系 - URL 中的变量(如 phonemessearch2.php?phon1=M&phon3=L&phon4=IY&umatch=umatch
)将在 $_GET
中,而不是 $_POST
中。