Pass Parameters from one PHP to Another, on Localhost, not using HTTP requests, includes, or sessions-ThrowExceptions

Exception or error:

I want to track and save to my local DB any event where my website’s users click on links.
the user ID is saved in session information.

Links are structured like this: , with 1234 being example for concrete link user want to go to.

Right now, on go.php, I use _GET and then redirect to user to the actual link (by searching another DB table to find the matching link for the d value, such as 1234.

I want the tracking to happen simultaneously, on server side only, in order to avoid slowing or undermining the redirection process of the user.

Therefore, my idea is to have go.php call another php script on my localhost – track.php.
And inside track.php do an INSERT with the user’s data into another DB table, so if anything fails with the insertation, user will not be affected.

How can I pass data like the user’s ID and the link ID that was clicked (and other info I plan to collect, such as user agent, resolution, referrer page, etc), under those requirements?

  • I can’t use session since session are stored on the user’s machine and I don’t want user to have any interaction with this script, and even if session is stored on server, there can be multiple users who will click the same time on links and overwrite the session info I guess.

  • I don’t want to pass info via a URL and use _GET to extract it, since I don’t want to use an HTTP request, it makes no sense to use one (speed and security perspective), if everything should happen on my local host.

  • I don’t want to use an include since like I said, if anything in the track.php code will fail, if it is included within go.php, this can cause fatal error and undermine the redirection process.


Is it possible for example to trigger track.php, the same way as cron jobs are triggered?

For example, If one can set a cron job like:

php /home/user/backend/track.php user_id=1 link_id=1234 user_agent="mozilla 1.7/85"

and pass parameters this way, so maybe in script I can do something like:

some-php-function(php /home/user/backend/track.php user_id=1 link_id=1234 user_agent="mozilla 1.7/85")

So maybe something like:

shell_exec(php /home/user/backend/track.php user_id=$u_id link_id=$l_id user_agent="$agent");

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *