473,327 Members | 2,118 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

How do I preserve the host name?

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

http://mine.com/myscript.php

and I want to call

https://mine.com/secure.php. 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

https://www.mine.com/secure.php, which is bad because on Mozilla I lose
my session cookie if I go from mine.com to www.mine.com.

Any help is greatly appreciated, - Dave

Jul 17 '05 #1
3 1329
Hey, use this as your form action to cut of the www.:

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

Jul 17 '05 #2
la***********@zipmail.com wrote:
http://mine.com/myscript.php
and I want to call
https://mine.com/secure.php. 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
https://www.mine.com/secure.php


Take a look at the output of phpinfo(32); Probably HTTP_HOST contains
the requested mine.com, 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://%{HTTP_HOST}/$1 [R,L]
RewriteRule ^/(.*):NOSSL$ http://%{HTTP_HOST}/$1 [R,L]

Jul 17 '05 #3
*** la***********@zipmail.com escribió/wrote (11 Mar 2005 11:41:55 -0800):
action="<?php print "https://" . $_SERVER['SERVER_NAME'] .
"/secure.php"; ?>

but the resulting url is

https://www.mine.com/secure.php, which is bad because on Mozilla I lose
my session cookie if I go from mine.com to www.mine.com.


I believe the server name is fixed, no matter the URL. You should use
$_SERVER['HTTP_HOST']
--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (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
--
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jan Keller | last post by:
Hello all, I am using an XmlTextReader and a DataSet to populate a DataGrid: ds = New DataSet xr = New XmlTextReader(path) ds.ReadXml(xr) xr.Close() dv = New DataView(ds.Tables.Item(0))
11
by: Brian W | last post by:
Yet another editor problem To reproduce do the following 1) Open a Webform and switch to HTML edit mode 2) Enter the Following (include spaces) This is some text before <asp:hyperlink...
2
by: Jeff | last post by:
I have an ASP.NET web page accessing a SQL database. I've used VS to build the app and stored it in the eNPTest02 directory of my localhost on my development machine. The database is on the web. ...
6
by: Brian Henry | last post by:
is there a way to get the host name of someone? like mine is 68-23-123-123-pitt-pa.adelphia.net? Request.UserHostName doesn't seem to return the host name like it states in the documentation,...
7
by: Sakharam Phapale | last post by:
Hi All, How to preserve the old font properties while changing new one? I posted same question 2 months back, but I had very small time then. eg. "Shopping for" is a text in RichTextBox and...
1
by: soup_or_power | last post by:
I am unable to preserve white space. Here is my code: public class xml { public static void main(String args) { try{ String jaxpPropertyName = "javax.xml.parsers.SAXParserFactory"; if...
23
by: Bjorn | last post by:
Hi. Every time i post data in a form the contents are being checked for validity. When i click the back-button, all data is gone and i have to retype it. It's obvious that only a few or none of...
2
by: red_valsen | last post by:
I have a default installation of SQLServer2000 on a host running Win2003. I want to install SQLServer2005 on the same machine, but preserve the original SQLServer2000 installation. How do I do...
4
by: n.phelge | last post by:
I need to perform an XSLT to set the namespace on some XML and I need to preserve the original document line formatting to assist with error handling (so the line number from any schema validation...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.