Apache-PHP question

hegde123
hegde123 used Ask the Experts™
on
Hi
  i'd like to know if this scenario is possible and if so how?...We have PHP running on a apache server on port 8080. I'd like to know if its possible to have user come in on a diffrent port, say 8090 which redirects them to a different login page than on port 8080 and have a separate authentication for them using the same web server though.

example: user 1 comes in on 8080 and hits the login page on index.php. This is what currently happens.

I need User 2 to come on on another port 8090 and when so hits a different login page. If its possible to direct them to say index2.php etc.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
The simplest way to accomplish this is to create another httpd.conf for the second server, and start a second instance of apache using :

"httpd -f /path/to/other/httpd.conf"

In that conf file, you can specify the second port number and set a different default page in the same document root, or specify a separate document root altogether.

Hope that helps,

David

Author

Commented:
I'd like to actually do this using the same web server.so basically have one web server access 2 index files depending on which port the user comes in.

Commented:
in my senario, it is the same web server, you are just starting two instances of it, one listening on each port.
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.


On httpd.conf or .htaccess:

RewriteEngine On
RewriteCond  %{SERVER_PORT}     ^8090
RewriteRule  ^.*$               /path/to/login8090.php

You need mod_rewite, of course.
I didnt tested, but shoud work.


On httpd.conf or .htaccess:

RewriteEngine On
RewriteCond  %{SERVER_PORT}     ^8090
RewriteRule  ^.*$               /path/to/login8090.php

You need mod_rewite, of course.
I didnt tested, but shoud work.

Why can't you create a vertiual host with different post specified . In this configuarion if you header is different site is different and if the port is different then the site is different. It will be easy and will make a another url for you like

www.test.com:8080 is different from with document root /www/8080port/
www.test.com:8090 with document root /www/8090port/

Good Luck
Harry

Commented:
You can have two "Listen" directives in your apache configuration.  "Listen 8080" and "Listen 8090".  (Two seperate lines.)  Then, in your normal index.php, just check $_SERVER["HTTP_HOST"] to see if it's coming in on port 8080 or port 8090.  Then you can just redirect to index2.php if it's port 8090.  And you don't need to setup any other virtual hosts or directories.

  -- Rob
Commented:
Side note:

When checking $_SERVER["HTTP_HOST"], you need to know that it includes the host name before the port, seperated by a colon (standard syntax).  So this is how I would handle it:

$tmp = explode(":", $_SERVER["HTTP_HOST"]);
$port = $tmp[1];
if ($port == 8090)
{
  header("Location: index2.php");
  exit();
}

  -- Rob

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial