• PHP Help PHP Newbies
  • is there a php equivalent of this JS >> "varURL = document.location.href"

Hi

Is there any php that does the equivalent of this javascript:

<script language = "JavaScript">
<!--

function whatsMyUrl(){

thisUrl = document.location.href;

}

//-->

</script>[/COLOR]

Can it be done? For some reason I won't bore you with I can't use the javascript (damn IE...grrr) if theres something like that in PHP then all my problems are solved.

thanks for your time 🙂

    ok... only new to this so there might be a better way, but this should do it.

    function whatsmyurl()
      {
        $tmp = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];
        return $tmp;
      }
    

      thanks mate I'll give that a shot!

      I had something working just fine with JS, calling it from Flash. But as soon as the js was called all animated gifs on the page froze up!

        Hi Thorpe

        Bit stuck, this is what I've got:

        <?php

        function whatsmyurl()
        {
        $tmp = 'http://'.$SERVER['HTTP_HOST'].$SERVER['PHP_SELF'];
        return $tmp;

        echo "$tmp";

        }

        whatsmyurl();

        ?>

        testing it on my local server but its not doing anything, er....do you know what I need to do to get some url out of it?

        I'm a bit lost!

          You need to print the value returned:

          <?php
          function whatsmyurl()
          {
          	return 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
          }
          echo whatsmyurl();
          ?>

            Thanks laserlight, I'm fairly close to my end objective now.

            <?php
            function whatsmyurl()
            {
                return 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
            }
            
            $myUrl = whatsmyurl();
            
            //send it back to flash
            echo "&myUrl="."$myUrl";
            
            ?> 

            check out this page: http://www.nitrovortex.com/test/myPage.html

            now that sends back to the flash the url of the php. ie.

            http://www.nitrovortex.com/test/whatUrl.php

            If I can get the php to give me:

            http://www.nitrovortex.com/test/myPage.html

            then I have this problem totally sorted 🙂 not sure its possible though.

              this function will return the url of the page it is called from. of course, it needs to be a php file.

              explain what your are trying to do and we might be able to help.

                Thorpe, this is linked with the other thread about calling javascript from php.

                I have a flash mp3 player, you can see it working here: http://www.twice-as-nice.co.uk/album_details.phtml?show=tracks&album_id=24

                Now flash loads up, calls a JS function ("varURL = document.location.href" ) that passes the entire url above to flash, my flash then snips off the end of that url leaving just "album_id=24". I then use that var to send to a php file which queries the database returns a list of mp3s for my flash to play... PHEW!

                Now that alll works great except for one little thing, in IE calling that JS function directly from flash causes any animated gifs on the same page to stop looping.

                I know that sounds ridiculous but its true, it happens 🙁 If the whole world used Firefox I wouldn't be on here now!

                So I need to come up with a solution, I can't call the JS directly from flash so gives me 2 options:

                A) Use an alternative to that JS function to getting a url into flash

                😎 Use php as a go between, so instead of flash->JS I have flash->php->JS

                Hope all that makes sense and you can see what I'm trying to do!

                  Just to say I've solved it now, incase anyone with a similar problem searches and digs up this problem in the future, here's the solution:

                  Embed the flash with this code where you intend to place the flash:

                  <script language = "JavaScript">

                  varURL = document.location.href; 
                  
                  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="760" height="120">'+

                  '<param name="movie" value="flash/audioPlayer.swf">'+
                  '<param name="quality" value="high">'+
                  '<param name=flashvars value=myUrl=' + varURL+ '>'+
                  '<embed src="flash/audioPlayer.swf" flashvars=myUrl=' + varURL+ ' quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="760" height="120"></embed></object>');
                  </script>

                  Just to say a big thank you for all the people who spent time looking into this, was much appreciated 🙂

                  Good forum this, I'll be back here for hopefully more pleasant php questions!

                    Write a Reply...