简体   繁体   English

提示用户使用jquery注册?

[英]prompting the user to signup using jquery?

i want to do something in jquery, if the user wants to vote on something, and they are not logged in or registered, you prompt them to do something just like stackoverflow, when the orange pop up thingy comes up, but i was wondering how you work with jquery and sessions!! 我想在jquery中做一些事情,如果用户想要对某些东西进行投票,并且他们没有登录或注册,你提示他们做类似stackoverflow的事情,当橙色弹出的东西出现时,但我想知道如何你使用jQuery和会话! i just want a push in the right direction! 我只想推动正确的方向! :)) :))

You need to set a javascript variable in your code somewhere that says whether or not the user is logged in. This can be from the backend sessions or from a browser cookie that you set. 您需要在代码中的某个位置设置javascript变量,该变量说明用户是否已登录。这可以来自后端会话或您设置的浏览器cookie。 You definetly don't want this to be the only measure against voting if they are not logged in though. 如果您没有登录,您绝对不希望这是唯一的反对投票的措施。 Check it on the server as well. 也请在服务器上查看。

If you want to use sessions, you can do something like this: 如果要使用会话,可以执行以下操作:

<script type="text/javascript">
    var userLoggedIn = <?php =$_SESSION['logged_in']; ?>
</script>

$_SESSION['logged_in'] would have to be set to either true or false . $_SESSION['logged_in']必须设置为truefalse Then you just check that variable ( userLoggedIn ) every time the user wants to perform an action. 然后,您只需在用户每次要执行操作时检查该变量( userLoggedIn )。 Also check it on the server-side as I said above. 就像我上面所说的,还要在服务器端检查它。

SO seems to use this method. 所以似乎使用这种方法。 If you look in the code, there is a line var isRegistered = true , which means that I am currently logged in. 如果您查看代码,则行var isRegistered = true ,这意味着我当前已登录。

Another way you could do it is to remove all voting functionality if they are not logged in, and add it when they are. 另一种方法是删除所有投票功能,如果他们没有登录,并在它们出现时添加。 This would save on load time for those who aren't logged in. 这将节省未登录的用户的加载时间。

Sessions are managed on the server and have nothing to do with jQuery. 会话在服务器上进行管理,与jQuery无关。

You can use jQuery to make nice modal dialogs for login screens, but that's just fancy HTML. 您可以使用jQuery为登录屏幕制作漂亮的模态对话框,但这只是花哨的HTML。

Without knowing what your setup is (ie if you're using a framework, etc) it's hard to give the best possible answer; 在不知道你的设置是什么的情况下(例如,如果你使用框架等),很难给出最好的答案; however, in general terms you'd just have to do the following: 但是,一般而言,您只需要执行以下操作:

  1. Check if the session is set and 检查会话是否已设置,以及
  2. If it is, launch the javascript popup. 如果是,请启动javascript弹出窗口。

Assuming the login session info is stored in a slot called 'username', you would do: 假设登录会话信息存储在名为“用户名”的插槽中,您可以执行以下操作:

if (!isset($_SESSION['username'])) { 
   print("
      <script type type=\"text/javascript\">
         alert('Please login first.');
      </script>
   ");
}

I recommend looking into jQuery UI for great ways to make things look more appealing. 我建议研究一下jQuery UI ,以获得使事物看起来更具吸引力的好方法。

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

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