如何在PHP中使用带变量的会话
我是PHP新手。我想使用带有变量的会话。这是我第一次玩session。我创建了4页 1。is session1.php如何在PHP中使用带变量的会话,php,session,Php,Session,我是PHP新手。我想使用带有变量的会话。这是我第一次玩session。我创建了4页 1。is session1.php <?php session_start(); $_SESSION['UserID']='1'; ?> <?php // starts session session_start(); if($_SESSION['UserID']='1') { header("location: user.php"); } if($_SESS
<?php
session_start();
$_SESSION['UserID']='1';
?>
<?php
// starts session
session_start();
if($_SESSION['UserID']='1')
{
header("location: user.php");
}
if($_SESSION['UserID']='2')
{
header("location: mang.php");
}
?>
<?php
echo "This is User page";
?>
<?php
echo "This is manager page";
?>
2。is session.php
<?php
session_start();
$_SESSION['UserID']='1';
?>
<?php
// starts session
session_start();
if($_SESSION['UserID']='1')
{
header("location: user.php");
}
if($_SESSION['UserID']='2')
{
header("location: mang.php");
}
?>
<?php
echo "This is User page";
?>
<?php
echo "This is manager page";
?>
3.user.php
<?php
session_start();
$_SESSION['UserID']='1';
?>
<?php
// starts session
session_start();
if($_SESSION['UserID']='1')
{
header("location: user.php");
}
if($_SESSION['UserID']='2')
{
header("location: mang.php");
}
?>
<?php
echo "This is User page";
?>
<?php
echo "This is manager page";
?>
4.mang.php
<?php
session_start();
$_SESSION['UserID']='1';
?>
<?php
// starts session
session_start();
if($_SESSION['UserID']='1')
{
header("location: user.php");
}
if($_SESSION['UserID']='2')
{
header("location: mang.php");
}
?>
<?php
echo "This is User page";
?>
<?php
echo "This is manager page";
?>
在我的代码中存在IF条件的问题。如果我的情况不起作用。你们能帮我解决一下我的问题吗
if($_SESSION['UserID']='1') and if($_SESSION['UserID']='2')
到
而且您已经在session1.php
中启动了会话,因此无需在session.php
最终产量
<?php
include ("session1.php");
if($_SESSION['UserID']=='1')
{
header("location: user.php");
exit;
}
if($_SESSION['UserID']=='2')
{
header("location: mang.php");
exit;
}
如果你解释我的(空白)不起作用或不起作用,通常说“我的(空白)不起作用”会很有帮助;如果它给出了一个错误,告诉我们错误@下面是我问题的答案。如果您必须使用比较运算符而不是赋值运算符,请将会话['UserID']='2'
更改为会话['UserID']='2',您的问题是因为输入错误而出现的。@KanishkaPanamaldeniya Stackoverflow说在我标记为接受您的答案后等待几分钟。多谢各位