Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8175841
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:55:14+00:00 2026-06-06T22:55:14+00:00

This question is similar in concept to this one , except I see I

  • 0

This question is similar in concept to this one, except I see I need more deep integration with Apache.

I am authenticating users via PHP and setting a cookie with a session ID that can then be looked up in a database table to find the user name. I need to also set the REMOTE_USER variable in Apache so I can pass that variable via an AJP connection and a regular HTTP connection to other application servers to use which can’t be set to read the information from a cookie.

It appears I need to integrate more deeply with Apache (Version 2), perhaps even writing a module, to do this properly. Does anybody have any example of how this might be accomplished with as little non-PHP glue code as possible? While I’m certainly familiar with several other languages, I was hoping to keep this project as simple as possible for those who will have to maintain it after me.

Thanks for any pointers!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:55:17+00:00Added an answer on June 6, 2026 at 10:55 pm

    PHP does not provide PHP scripts access to Apache variables. Although there is a function to set environment variables, it is reported that it does not set REMOTE_USER.

    You can do what you want before PHP handler starts and after it ends by adding other handlers to phases before and after PHP works. You can write your handler functions in C; but since you mean to have a solution that PHP programmers can access after you, I believe Python is a very good alternative.

    mod_python allows you to do this very easily. If you go to its website, you can see that its last update is February 2008; but it is mature and stable. They do not continue development because the current Python-Apache integration continues on mod_wsgi instead of mod_python. Since mod_wsgi sticks with WSGI, it does not provide Apache-specific functionality as mod_python does.

    After installing mod_python, all you need to have is writing simple functions that will run when you want them to. Below is an example of running two functions before and after PHP so you can access a cookie that was set by PHP.

    Apache Configuration:

    # Enable mod_python:
    LoadModule python_module modules/mod_python.so
    
    # Enable it as a handler:
    AddHandler mod_python .py
        # extension does not matter since we are not setting contentHandlers.
        # py files will continue being served as text/plain if you have any of them
        # under your document root.
    
    # Handler that will run before PHP:
    PythonFixupHandler set_auth_user
    
    # Handler that will run after PHP:
    PythonCleanupHandler set_auth_user
    

    This configuration needs set_auth_user.py where Python can import it. You can put it in site-packages folder of Python installation.

    Here is our Apache module written in Python:

    # -*- coding: utf-8 -*-
    from mod_python import apache
    
    def fixuphandler(req):
        apache.log_error("starting :"+str(req.headers_out.get('Set-Cookie')))
        return apache.OK
    
    def cleanuphandler(req):
        apache.log_error("cleaning up: "+str(req.headers_out.get('Set-Cookie')))
        req.user='hasanyasin' #this is how you update AUTH_USER
        return apache.OK
    

    Here is our PHP file:

    <?php
    setcookie('abc','foobar');
    ?>
    

    Here is my Apache log after a request is made to server:

    [Sun Jul 01 15:29:31 2012] [error] cleaning up: None
    [Sun Jul 01 15:29:31 2012] [error] cleaning up: abc=foobar
    

    I hope this solves your problem the way you needed. I added two handler functions for demonstration. If you need only one of them, remove the line in Apache configuration so there won’t be a useless method call for every request.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question is similar to this one How do I add options to a
This question is similar to this other one , with the difference that the
This question is similar to Getting Emacs fill-paragraph to play nice with javadoc-like comments
This question is similar to this: Asp.net Profile Across Sub-Domain I'm basically wondering if
This question is similar in spirit to : https://stackoverflow.com/questions/492178/links-between-personality-types-and-language-technology-preferences But it is based specifically
This question is similar to GWT Table that supports sorting, scrolling and filtering However
This question is similar to Why are methods in Ruby documentation preceded by a
I know this question is similar to several previous ones, but I can't find
This question is very similar to an earlier question I asked ( This Question
My question is similar to this MySQL question, but intended for SQL Server: Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.