Take the 2-minute tour ×

I have a question which I think should be fairly simple, but I can't seem to make it work for some reason. What I want to do is have a button which when clicked on performs the following:

  1. Use jQuery and Ajax to start a first php function. This function checks if the user is logged in by checkign session variables. If he/she is, the function returns false, and if he/she is not, it returns an url.
  2. If the url is returned the jQuery should then use this url and open a new window by using the script displayed down low.
  3. At the same time a second php function is opened, which contains a loop to check for the session variable. This loop returns true when the session variables are found (I know it's possible through jQuery to let it check every second or so, but again I couldn't remember it so I did it in the php script.
  4. If true the jQuery adds a class to the button, changing its appearance.

I hope this was clear. Normally I think it would have been no problem for me, but I've been burried in PHP so deep for the last couple of months and seem to have forgotten most of my jQuery basics.

I guess this is how it should basically look like, but I'm stuck. I hope you can help. If you have any additional questions please let me know.

The button

<a id="inlog_button">Login button</a>

and this is my best guess what the jQuery should look like:

$(document).ready(function () {  
       url: "first_function.php";  
 //need to get result, if url is return than launch new window  

var newwindow;
        width    = 1000,
        height   = 630,
        left     = parseInt(screenX + ((outerWidth - width) / 2), 10),
        top      = parseInt(screenY + ((outerHeight - height) / 2.5), 10),
        features = (
          'width=' + width +
          ',height=' + height +
          ',left=' + left +
          ',top=' + top

        newwindow=window.open('url returned from above function here','Login here',features)

//start loop checking for session variable and post new sessions, if first session is found return true and set 3 new

//see if function returns true, if so add class to button and add disabled state, so it can't be presses again. And that's it.


Best regards,

Marcus Joe

share|improve this question
Why wait for the jax call? I would perform this check in php before serving the page and prepare the button to open the link. –  Matt Jan 28 '11 at 11:40
Yes you are right, I should do that. However the rest of the script should than still be performed on click. So the window should be opened and the second function should be called to check for the session variable and to return true andadd the other session variables afterwards. Then that result should be taken and if true add the class and state of the button. –  Marc Hoogvliet Jan 28 '11 at 11:44

Your Answer



Browse other questions tagged or ask your own question.