Php 如何在数组和签出页面中执行受限URL

Php 如何在数组和签出页面中执行受限URL,php,Php,我想限制签出.php的页面和我的账户.php的页面。我像这样在top.php上添加了这些限制 $current = $_SERVER['PHP_SELF']; $url = "http://" . $_SERVER['HTTP_HOST'] . $current; $restricted = array("<a href='" . BASE_URL . "products/check_out.php'>Check Out</a>, <a href='" . BASE

我想限制签出.php的页面和我的账户.php的页面。我像这样在top.php上添加了这些限制

$current = $_SERVER['PHP_SELF'];
$url = "http://" . $_SERVER['HTTP_HOST'] . $current;
$restricted = array("<a href='" . BASE_URL . "products/check_out.php'>Check Out</a>,
<a href='" . BASE_URL . "users/my_account.php'>My Account</a>");
$public_pages = array("login.php","signup.php");
$current=$\u服务器['PHP\u SELF'];
$url=“http://”$_服务器['HTTP_HOST']$现在的
$restricted=数组(“,
");
$public_pages=array(“login.php”、“signup.php”);
它工作不好!没有登录。签出页面仍在打开

当用户单击下面的链接时。 它需要检查条件,如如果用户登录,则进入签出页面。否则,它将转到singup.page

<li><a href="<?php echo(BASE_URL); ?>products/check_out.php"> Check Out </a></li>
  • 这是条件代码,我现在所做的

    if ($obj_user->login && in_array($current, $public_pages)) {
      $_SESSION['ref_url'] = $url;
      $_SESSION['msg'] = "You must <a href='" . BASE_URL . "/process/process_logout.php'>LOGOUT</a> to view this page";
    header("Location:" . BASE_URL . "msg.php");
    }
    
    if (!$obj_user->login && in_array($current, $restricted)) {
     $_SESSION['ref_url'] = $url;
     $_SESSION['msg'] = "You must <a href='" . BASE_URL . "/login.php'>LOGIN</a> to view this page";
     header("Location:" . BASE_URL . "/msg.php");
    }
    ?>
    
    if($obj\u user->login&&in\u数组($current,$public\u页面)){
    $\会话['ref\u url']=$url;
    $\u SESSION['msg']=“您必须查看此页面”;
    标题(“位置:“.BASE_URL.msg.php”);
    }
    if(!$obj_user->login&&in_数组($current,$restricted)){
    $\会话['ref\u url']=$url;
    $\u SESSION['msg']=“您必须查看此页面”;
    标题(“位置:“.BASE_URL./msg.php”);
    }
    ?>
    
    在Check_out.php中,我已经设置了显示数量、产品名称和总价的表格

    谢谢

  • 把你的第一行改成这个

    $current=basename($\u SERVER['PHP\u SELF'])

  • 将$restricted数组更改为此

    $restricted=array('check_out.php','my_account.php')


  • 在任何一个非公共php文件中,添加一个检查,如果用户未登录,则重定向到注册页面。 将您的签入添加到任何非公共php文件的顶部

    //Make sure your session has started 
    //Check the user if he/she is not logged in, assuming this will return true or false if the users session is set.
    if(!$obj_user->login){
       //redirect to the sign up page e.g
       header("Location: signup.php");
    }
    

    您可以在这些服务器上使用重定向pages@Ali,为什么不使用$\u会话来检查登录与否?如果不存在,只需检查签出页面上的会话即可注册返回page@devpro$\会话已启动top.php。会话中存储的购物车信息。所以用户还没有登录。这就是为什么直到他/她注册或登录。这是怎么做到的@阿里,你在不登录的情况下存储购物车数据?你在使用什么框架吗?是的,这样做了!它限制了check_out.php页面!现在如何重定向signup.php页面!现在有一件事弄糊涂了。在signup.php之后。我必须返回check_out.php页面。如果是通过check_out.php,在singup或login.php之后,请在check_out.php中输入上述代码,以检查用户是否登录。该代码将检查用户是否未登录,然后重定向到注册页面。在signup.php之后,我想再次重定向到签出页面!如何?注册后,为当前注册的用户创建会话。创建会话后,使用标题(“Location:check_out.php”);很高兴你拿到了:D