PHP - Moved: Trigger Event When Browser Is Closed
This topic has been moved to JavaScript Help.
http://www.phpfreaks.com/forums/index.php?topic=352282.0 Similar TutorialsOK, I'm nearing the end of a very long chat project and I have one last hurdle to jump, I've saved this task to the near end because I thought it would be a problem as I have no idea what to do or where to start. The problem is exactly what is said in the subject title. I have looked into JavaScript options such as "onbeforeunload" but that is just BAD. The login is controlled by sessions, so when the user closes the browser, the session is ended, but data in the database says different, cookies are not an option I'm afraid. I've had an idea that if I create a special account (or a few) and always leave these accounts logged in, they can check if a user has been inactive for a certain period of time, and then run queries to change things, I know this sound odd but maybe I will not have to create these accounts but general accounts that people make will be able to do this for me, without them even knowing. Please help, any ideas, suggestions, logic or methods that you think will help will be great. Thanks. Hello, How do I get a user's session destroyed when he closes his browser? Thanks in advance I made a bug which caused endless loop and endless printing. When I noticed that, I closed the browsers tab, fixed the bug, open a new tab and re-run. I was assuming the server would start from the beginning, but instead I noticed that some variables were active and the program continued from where it stopped. How can I make the program to stop when the client tab is terminated? Hey All, I have a sessions table that is used to see if a user is online. It only gets deleted when they click the Logout button. What I need to do is have it so it gets deleted even if they close the browser. Should I add a column in the sessions table with a time stamp and check on each page for every user to make sure its great than 30 min? Is there a better way to do this, without so many queries? Thanks This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=346932.0 This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=330163.0 i am trying to set user status as offline when user close browser but i am facing a problem ... i am calling a function when body unload which will set guest user status to "0" when user close the browser but it not working ... it execute php before function is called.. any idea why this is happening ...please help it's making me crazy This topic has been moved to Third Party PHP Scripts. http://www.phpfreaks.com/forums/index.php?topic=348839.0 This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=346338.0 This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=342929.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321426.0 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=314530.0 This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=348773.0 This topic has been moved to CSS Help. http://www.phpfreaks.com/forums/index.php?topic=319246.0 I have a listener which executes a HTTP request to a remote API before the User entity is persisted and uses the response to set one of the entity's properties. It will also listen for update and remove and will make the appropriate HTTP request to the API but will not modify the entity. All works as desired... Almost. If when persisting the entity, I have some error, the remote API and my application become out of sync. I wish to change my application to perform a second call to the API if an error occurs and reverse the previous call. My thoughts on how to implement a Place a try/catch block when executing the query. Don't like this approach. Add an ExceptionListener which somehow retrieves the entity and makes the applicable changes. Maybe part of the solution, but too complicated to be the full solution. When adding, updating, or deleting a user from the remote API under UserListener's three methods, adding a callback which gets executed upon a PDOException. I think this is the best approach and expanded my thoughts below.
<?php namespace App\EventListener; use Doctrine\Persistence\Event\LifecycleEventArgs; use App\Service\HelpDeskClient; use App\Entity\AbstractUser; final class UserListner { private $helpDeskClient; public function __construct(HelpDeskClient $helpDeskClient) { $this->helpDeskClient = $helpDeskClient; } public function prePersist(AbstractUser $user, LifecycleEventArgs $event) { $this->helpDeskClient->addUser($user); //$user will be updated with the HTTP response } public function preUpdate(AbstractUser $user, LifecycleEventArgs $event) { $this->helpDeskClient->updateUser($user); } public function preRemove (AbstractUser $user, LifecycleEventArgs $event) { $this->helpDeskClient->deleteUser($user); } } Okay, how do I actually do this? Was thinking of modifying UserListner as follows: //... use Symfony\Component\HttpKernel\KernelEvents; final class UserListner { // ... public function prePersist(AbstractUser $user, LifecycleEventArgs $event) { $this->helpDeskClient->addUser($user); $event->getObjectManager()->getEventManager()->addEventListener(KernelEvents::EXCEPTION, function($something) use($user) { // Use $this->helpDeskClient to reverse the changes }); } // Similar for update and remove }
But when trying this approach, I get a PDOException, but my callback never gets excecated. I've also tried replacing KernelEvents::EXCEPTION with '\PDOException' (note the quotes) with no success. Any ideas what I should be doing differently? Maybe some totally different approach? I suppose I could make the request to the API after the DB query is complete for updating and deleting, but not for adding. This topic has been moved to HTML Help. http://www.phpfreaks.com/forums/index.php?topic=316203.0 I want to create a sort trigger, group by and order by on a table after insert. Should the trigger be of this nature create trigger triggername after insert on tablename for each row begin insert into table (column1, column2 ) values ( value1, value2) group by column1 order by column1 end; Hello dear friends, let say we have (function) and that function has one variable which is (id) the (id) could be number any number 1 or 4 or even 49999 whatever. how to make closed loop which i mean run this function in unlimited way each time with new id <--- i can do it by set random() but the problem i've is how to make it repeat itself excuted excuted excuted | | | ect let say for example , i will insert random number in at database table Code: [Select] $id = rand(); mysql_query("INSERT INTO comments(id) VALUES ('$id')"); that is it, how then i can repeat it many many times without 1) refresh 2) rewrite it many times thanks in advance How can I create a PHP script that will trigger a download?
For example, if I have a database of files and file IDs, and have a hyperlink like this in an HTML page:
getfile.php?FileID=1001
How can I code the getfile.php file so that no matter what type the file is (ZIP, EXE, JPG, AVI, etc), it will cause the browser to prompt the user to download the file?
(Not entirely sure if this is more a PHP question or an HTML question because of how I'm approaching it...)
(The purpose of me using the getfile.php file is so that files can be physically moved around without me having to update all of the hyperlinks in the HTML files, but rather just update the paths in the SQL database instead.)
Edited by cbassett03, 02 September 2014 - 11:25 PM. Hi,
I have an adverts table that has records of currently running adverts, i have not used stored procedures or triggers before.
I would like to create a stored procedure or a trigger using phpmyadmin for mysql.
Exactly what i want to achieve is, when a record is accessed in adverts table, it causes a table called HITS to create a record that has the adverts_id, IP where the advert was clicked from, current date.
Is that possible?
|