Web Analytics Made Easy -
StatCounter How to find url in php - CodingForum

Announcement

Collapse
No announcement yet.

How to find url in php

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to find url in php

    Hello all,

    If my site has two domains, but domain one should point to french which already works.

    but domain 2, how can I check the url and if url is let's say domain2.com then add lang=en to the query string.

    Thanks

  • #2
    In pusedo code... (don't comment on my spelling... ).

    Code:
      1. Get the domain name
           - you should be able to use [COLOR="Blue"]parse_url[/COLOR]() for this.
      2. Check the domain to see if it the english or french.
           - possible to use if else statments.
      3. If it is english, redirect 
           - using headers would work...
           - make sure that on the top of the website have a code saying:
                  if($lang=="en" || $lang=="fr") {
                       // Do not redirect
                  }
                - this is to prevent looping
    At least, that's the way I'd think about doing it.
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

    Comment


    • #3
      how do I get the domain name

      every example of parse_url() on the internet assumes you already have the domain name.

      Can anyone help me out?

      Comment


      • #4
        PHP Code:
        echo '<pre>';
        print_r($_SERVER);
        echo 
        '</pre>'
        look at the variables in there

        Comment


        • #5
          Thanks

          I'll try that out, documentation for parse_url() is horrific!

          So $_SERVER is the best approach?

          Comment


          • #6
            Now that I look at it yes... the $_SERVER should get the domain name for you... however it will get the domain name for the current domain shown in the top.
            Dawson Irvine
            CEO - DNI Web Design
            http://www.dniwebdesign.com

            Comment


            • #7
              after getting the domain name how would I go about appending a language query string appended to the querystring?
              Last edited by LondonBoy; Oct 4, 2006, 01:00 PM.

              Comment


              • #8
                Code:
                $_SERVER['HTTP_HOST']
                Last edited by marek_mar; Oct 4, 2006, 01:05 PM.
                I'm not sure if this was any help, but I hope it didn't make you stupider.

                Experience is something you get just after you really need it.
                PHP Installation Guide Feedback welcome.

                Comment


                • #9
                  If I made this code:

                  $host = $_SERVER['HTTP_HOST'];

                  if (!isset($lang)) {
                  if ($host=="www.domain1.com") {
                  $lang=fr;}
                  if ($host=="www.domain2.com") {
                  $lang=en;}
                  }


                  From there, how would I append the lang variable in the URL?
                  There might or might not be a querystring already initiated, so I may start with & or with ?

                  Would anyone know this?

                  Comment


                  • #10
                    any1 plz

                    Comment


                    • #11
                      http_build_query() (or the PHP4 implementation.
                      Checking for the '?' is easy.
                      PHP Code:
                      <?php
                      if(strpos($url'?') !== false))
                      {
                         
                      // Query string is there. Add a "&"
                      }
                      else
                      {
                         
                      // No query string. Add a " ? "
                      ?>
                      I'm not sure if this was any help, but I hope it didn't make you stupider.

                      Experience is something you get just after you really need it.
                      PHP Installation Guide Feedback welcome.

                      Comment

                      Working...
                      X