简体   繁体   English

Processwire-PHP-如果单击链接

[英]Processwire - PHP - if link is clicked

I have a button on my page that if clicked opens a modal that allows user to create a topic. 我页面上有一个按钮,如果单击该按钮,将打开一个模式,允许用户创建主题。 I want to implement some checks, if user if logged in allow to create IF not then forward to login page. 我想执行一些检查,如果用户登录后允许创建IF,则不转发到登录页面。 AS testing I have made IF logged in > forward to "/" IF not then for to "/login" AS测试中,我已使IF登录>转发至“ /” IF则不进行“ / login”

My code is currently as following, which does not work. 我的代码当前如下,这不起作用。 It always allows to create. 它总是允许创建。

//Check if user is logged in before allowing to create
if (isset($_GET['create'])) { 

    //Check if current user is logged in 
    if ($user->isLoggedin()) { 

        $session->redirect("/");

    }

           //If current use not logged in redirect to login
    else {

        $session->redirect("/login"); 
    }
}
<a href="#?create" role="button" name="create" class="btn btn-success btn-block" data-toggle="modal" data-target="#basicModal">

You have have to check session before enter into create code. 在输入创建代码之前,您必须检查会话。

session_start();
if(!isset($_SESSION['sess_user_id']) || (trim($_SESSION['sess_user_id']) == '')) {
header("location: login.php");
}

It's hard to answer this for sure without knowing what you are passing in the url to this page. 在不知道您要传递到此页面的URL中的情况下,很难肯定地回答这个问题。 You could have ?create=&somethingelse=true and the isset for create would still be true. 您可能具有?create =&somethingelse = true,并且create的isset仍然为true。

Also, in Processwire you can use: 此外,在Processwire中,您可以使用:

$input->get->create

If you can provide more information on the url that is being used to access this page, I am sure it will be easy to fix. 如果您可以提供有关用于访问该页面的URL的更多信息,我相信它将很容易修复。 Is it the url that is coming from the create button code at the end of your code block? 是来自代码块末尾的“创建”按钮代码的url吗?

Is this code in a PW template php file, or is it a bootstrapped script? 此代码是在PW模板php文件中,还是自举脚本?

Something else that is confusing about your code is the href line at the end - it is html? 令您的代码感到困惑的其他事情是最后的href行-它是html吗? You never closed your php tags from the code above. 您从未从上面的代码中关闭过php标签。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM