I have a web site which uses PHP code to check for a cookie set by our corporate authentication server, and look up the account in an ACL in my database. Among other things, I need to make sure a customer cannot see other customer’s data.
Now, I have been given customer specific reports, in HTML and possibly binary formats, which of course do not have my PHP code to check the authentication and authorization. I would like to write a single PHP file, and have all requests under a certain directory to be processed by that PHP file, which could then try to figure out the relative file path from the original URL and serve the file only if authorization passes.
So, if the URI is /report/customer-C/report-R/index.html, then instead of having this report in a sub-directory of the web-folder, the URL would be processed by get-report.php, which would check authorization, and get the file from a directory not accessible from the web-folder (i.e. not in a sub-directory).
I am using:
Windows Server 2003
Apache HTTP Server 2.2.3
PHP 5.1.4 (cgi-fcgi)
Mapping different URLs to one PHP script
Moderator: General Moderators
-
marlinpierce
- Forum Newbie
- Posts: 4
- Joined: Tue Jul 03, 2007 9:57 am
-
marlinpierce
- Forum Newbie
- Posts: 4
- Joined: Tue Jul 03, 2007 9:57 am
Alias Approach
I tried using Alias or ScriptAlias, without success.
Alias serves the file directly. ScriptAlias executes the file. I need to map the URL to the get-report.php file, but send that file to PHP.
I tried using ScriptAlias to a .CMD or .BAT file, which would call PHP.
In httpd.conf I have the following:
The contents of get-rpeort.bat are:
The contents of get-report.php are:
Running get-report.bat from the command line I get the following output:
When I make a request to my web server for http://srv/report/foo, I get the following page returned:
Alias serves the file directly. ScriptAlias executes the file. I need to map the URL to the get-report.php file, but send that file to PHP.
I tried using ScriptAlias to a .CMD or .BAT file, which would call PHP.
In httpd.conf I have the following:
Code: Select all
ScriptAliasMatch ^/report/.* "c:/get-report.bat"Code: Select all
echo before
\php\php-cgi -f \get-report.php
echo afterCode: Select all
<? print "I will have to find the file later.\n"; ?>Code: Select all
C:\>echo before
before
C:\>\php\php-cgi -f \get-report.php
I will have to find the file later.
C:\>echo after
afterCode: Select all
C:\>echo before
before
C:\>\php\php-cgi -f \get-report.php
C:\>echo after
after-
marlinpierce
- Forum Newbie
- Posts: 4
- Joined: Tue Jul 03, 2007 9:57 am
Redirect Approach
I tried redirect, which works, but the browser then has the redirected URL, and I am afraid that relative links in the HTML files will be broken.
In httpd.conf I have the following:
In the root of my web-folder I have the file get-report.php with the following contents:
When I make a request to my web server for http://w2kvnes-dev.opnet.com/report/foo.html, I get a page displaying the URI,
However, the browser address bar shows:
http://srv/get-report.php?fileaddr=/report/foo.html
If I actually return the contents of an HTML page, I expect that the browser would treat relative links as relative to get-report.php.
In httpd.conf I have the following:
Code: Select all
RedirectMatch ^(/report/.*) "http://srv/get-report.php?fileaddr=$1"Code: Select all
<html>
<head><title>Test</title></head>
<body><? print $_REQUEST['fileaddr']; ?></body>
</html>Code: Select all
/report/foo.htmlhttp://srv/get-report.php?fileaddr=/report/foo.html
If I actually return the contents of an HTML page, I expect that the browser would treat relative links as relative to get-report.php.
-
marlinpierce
- Forum Newbie
- Posts: 4
- Joined: Tue Jul 03, 2007 9:57 am
Rewrite Approach
I tried using Rewrite without success.
I uncommented the line in httpd.conf:
I added lines:
In the root of my web-folder I have the file get-report.php with the following contents:
When I request
http://srv/report/foo.html
I get the following returned in my browser:
I uncommented the line in httpd.conf:
Code: Select all
LoadModule rewrite_module modules/mod_rewrite.soCode: Select all
RewriteEngine On
RewriteRule ^(/report/.*)$ /get-report.php?fileaddr=$1Code: Select all
<html>
<head><title>Test</title></head>
<body><? print $_REQUEST['fileaddr']; ?></body>
</html>http://srv/report/foo.html
I get the following returned in my browser:
Code: Select all
No input file specified.