How do I preserve the host name?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

   Let's say my PHP 4 script can be accessed on

and I want to call .  Without hard coding the domain, how can I
incorporate "https"?  Right now, I'm trying

action="<?php print "https://" . $_SERVER['SERVER_NAME'] .
"/secure.php"; ?>

but the resulting url is, which is bad because on Mozilla I lose
my session cookie if I go from to

Any help is greatly appreciated, - Dave

Re: How do I preserve the host name?

Hey, use this as your form action to cut of the www.:

<?php print "https://" . substr($_SERVER['SERVER_NAME'],4) .
"/secure.php"; ?>

Re: How do I preserve the host name? wrote:
Quoted text here. Click to load it

Take a look at the output of phpinfo(32); Probably HTTP_HOST contains
the requested, else you have to strip like already suggested.

BTW I'd make the page that submits to an https url, itself https also. I
personally will not submit confidential info unless I know it will be
transmitted secure, if the form is on a http URL I'd hae to check the
source to find out what will happen.

Also that makes it possible to use a relative link, and since there is
nothing posted yet you can very easily force myscript.php to be a https
URL. If you are using apache the following will make it even more easy:

RewriteRule    ^/(.*):SSL$             https://%/$1 [R,L]
RewriteRule    ^/(.*):NOSSL$           http://%/$1 [R,L]

Re: How do I preserve the host name?

*** escribió/wrote (11 Mar 2005 11:41:55 -0800):
Quoted text here. Click to load it

I believe the server name is fixed, no matter the URL. You should use

-+ Álvaro G. Vicario - Burgos, Spain
+- (la web de humor barnizada para la intemperie)
++ Manda tus dudas al grupo, no a mi buzón
-+ Send your questions to the group, not to my mailbox

Site Timeline