Member Avatar for chudapati09
<?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.

Recommended Answers

All 2 Replies

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.

Member Avatar for chudapati09

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.