0

Can i do this?:

$(window).focus(function() {
<?php if(session....) ?>
...$.ajax...
<?php }else{
header('');
}
?>
});
1
  • have you tried it? what happened? Commented Nov 8, 2010 at 18:26

1 Answer 1

4

Yes you can, but keep in mind that the PHP if-else is executed on the server and only once, so the resulting JS will contain either the $.ajax call or nothing at all - this won't change once the page has loaded.

Also, you can't usually call header after you've already sent some output (unless you're using output buffering).

Sign up to request clarification or add additional context in comments.

2 Comments

Yes so what else can I do then to make it check more than once?
@Johnson: Then you have to write all the code in JavaScript. However, there's no way to access the PHP session from JavaScript. One way is to add another AJAX call to a PHP script that returns the value within the if statement, then check it in JavaScript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.