0
<?php

echo  '<script type="text/javascript">
         if(confirm("Your time has expired. Do you want to logout?"))
            alert("Five minutes were added on too your session"); //User will five minutes added on
         else
            alert("You are logged out"); //User will be loged out
      </script>';

?>

How do I put in PHP code inside the if statement and else statement. For example, in the if statement I want to do some SQL stuff, then in the else statement I want to again do some SQL stuff and a redirect.

Edited by chudapati09: n/a

2
Contributors
2
Replies
10
Views
6 Years
Discussion Span
Last Post by chudapati09
0

You need to remember that the PHP is all done when the Javascript executes in the Browser. Thus you can't casually go back and forth between the two. With some Ajax, you can get back to the server and have PHP do something for you (e.g. some SQL stuff) and return the result to the Javascript. I don't have any code to give you for that but someone probably will or you can do a search. You can't do a PHP re-direct from the Javascript but I believe that a window.location command in the javascript will accomplish the same thing.

0

Thanks, I will look into AJAX

You need to remember that the PHP is all done when the Javascript executes in the Browser. Thus you can't casually go back and forth between the two. With some Ajax, you can get back to the server and have PHP do something for you (e.g. some SQL stuff) and return the result to the Javascript. I don't have any code to give you for that but someone probably will or you can do a search. You can't do a PHP re-direct from the Javascript but I believe that a window.location command in the javascript will accomplish the same thing.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.