PHP Web Fundamentals Communicating Within Apache - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript PHP Web Fundamentals Communicating Within Apache - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Friday, May 31, 2019

PHP Web Fundamentals Communicating Within Apache

PHP Web Fundamentals



Communicating Within Apache

Problem

You want to communicate from PHP to other parts of the Apache request process. This includes setting variables in the access_log.

Solution

Use apache_note():

          // get value
          $session = apache_note('session');

          // set value
          apache_note('session', $session);

Discussion

When Apache processes a request from a client, it goes through a series of steps; PHP plays only one part in the entire chain. Apache also remaps URLs, authenticates users, logs requests, and more. While processing a request, each handler has access to a set of key/value pairs called the notes table. The apache_note() function provides access to the notes table to retrieve information set by handlers earlier on in the process and leave information for handlers later on.

For example, if you use the session module to track users and preserve variables across requests, you can integrate this with your logfile analysis so you can determine the average number of page views per user. Use apache_note() in combination with the logging module to write the session ID directly to the access_log for each request.

Example  Adding the session ID to the notes table

          // retrieve the session ID and add it to Apache's notes table
          apache_note('session_id', session_id())


No comments:

Post a Comment

Post Top Ad