Redirect the user and then register his visit using php and mysql

I have a PHP redirect page to track clicks on links. This basically does:

 - get url from $_GET
 - connect to database
 - create row for url, or update with 1 hit if it exists
 - redirect browser to url using Location: header

I was wondering if it is possible to first send the redirect to the client so that he can continue to work with this task, and then register the click. Would you just switch to work?

+3
source share
3 answers

You can do it:

  • get url from $_GET
  • send Location:headline
  • call flush()
  • connect to database
  • create a string for url or update with 1 hit if it exists

, , ( , - flush() ) , , Location: , , .

, , script . , pcntl_fork(); Apache SAPI.

+4
+1

. PHP , . , :

<?php
header('location: /');
sleep(2);
?>

2 .

0

Source: https://habr.com/ru/post/1705748/


All Articles