How do I preserve the host name?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • laredotornado@zipmail.com

    #1

    How do I preserve the host name?

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



    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

  • bass-man

    #2
    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"; ?>

    Comment

    • Daniel Tryba

      #3
      Re: How do I preserve the host name?

      laredotornado@z ipmail.com wrote:[color=blue]
      > 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[/color]

      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]

      Comment

      • Alvaro G. Vicario

        #4
        Re: How do I preserve the host name?

        *** laredotornado@z ipmail.com escribió/wrote (11 Mar 2005 11:41:55 -0800):[color=blue]
        > 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.[/color]

        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
        --

        Comment

        Working...