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!! i just want a push in the right direction! :))


Without knowing what your setup is (i.e. 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.

Assuming the login session info is stored in a slot called 'username', you would do:

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

I recommend looking into jQuery UI for great ways to make things look more appealing.

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. 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']; ?>

$_SESSION['logged_in'] would have to be set to either true or false. Then you just check that variable (userLoggedIn) every time the user wants to perform an action. 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.

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.

You can use jQuery to make nice modal dialogs for login screens, but that's just fancy HTML.

Need Your Help

Memory allocation testing between two devices

iphone memory-management

I am testing my app in two different devices. My app is relies heavily on images(allocating and deallocating). I know I have a leak but I am just curious why I observe this.

List (T) Databinding at Design Time

.net list data-binding datagridview

It's possible to bind the list to a data grid at runtime, like DataGridView.DataSource = MyList.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.