PHP help please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 3Xguru
    Confirmed User
    • Sep 2001
    • 1281

    #1

    PHP help please

    I want to make a script with a plug and play adult flash e-card that webmasters can put on their website. I have searched the web resources but I cannot seem to understand how to make the script load in a variable the adress of the script(the complete addres).


    So if the script is located at http://www.domain.com/script.php I want to load this URL into a variable dynamicaly, and if the script name is changed, so does the variable.

    Can anione help?
    -=Free Webmaster Tools=-
  • notjoe
    Confirmed User
    • May 2002
    • 5599

    #2
    Originally posted by 3Xguru
    I want to make a script with a plug and play adult flash e-card that webmasters can put on their website. I have searched the web resources but I cannot seem to understand how to make the script load in a variable the adress of the script(the complete addres).


    So if the script is located at http://www.domain.com/script.php I want to load this URL into a variable dynamicaly, and if the script name is changed, so does the variable.

    Can anione help?

    Create a file, phpinfo.php for example, and put <?phpinfo();?>
    . you will find the variable (and many more) in the output.

    Joe

    Comment

    • Rory
      Confirmed User
      • Jul 2002
      • 616

      #3
      $_SERVER['PHP_SELF'] will give you the path of the php file that is executing...... so do this :

      $current_page = $_SERVER['PHP_SELF'];
      $full_web = "http://www.yourdomain.com" . $current_page;

      Promote a site that actually retains members!

      Comment

      • Rory
        Confirmed User
        • Jul 2002
        • 616

        #4
        That will work for PHP 4.1+ .. for lower version numbers (get your ass current lol) try $HTTP_SERVER_VARS instead of $_SERVER . That should work even if php is buried in several different dirs. So DONT change the "http://www.yourdomain.com" part to something like "http://www.yourdomain.com/path/to" . Just thought I would clarify.

        Rory

        Promote a site that actually retains members!

        Comment

        • 3Xguru
          Confirmed User
          • Sep 2001
          • 1281

          #5
          Originally posted by Rory
          $_SERVER['PHP_SELF'] will give you the path of the php file that is executing...... so do this :

          $current_page = $_SERVER['PHP_SELF'];
          $full_web = "http://www.yourdomain.com" . $current_page;
          Yes, I understand the PHP_SELF part, but I also need the name of the domain to be loaded dynamicaly. How do I do that?
          -=Free Webmaster Tools=-

          Comment

          • Rory
            Confirmed User
            • Jul 2002
            • 616

            #6
            $_SERVER['HTTP_HOST'] then

            Promote a site that actually retains members!

            Comment

            • Rory
              Confirmed User
              • Jul 2002
              • 616

              #7
              So here is everything you need :
              PHP Code:
              $current_host = $_SERVER['HTTP_HOST'];
              $current_path = $_SERVER['PHP_SELF'];
              
              $full_web_path = "http://" . $current_host . $current_path; 
              
              Now the variable $full_web_path contains the correct info. The "http://" is optional. Like I said above if your PHP < 4.1 you will need to use $HTTP_SERVER_VARS instead of $_SERVER. So this would replace if you are running an earlier version of PHP :
              PHP Code:
              $current_host = $HTTP_SERVER_VARS['HTTP_HOST'];
              $current_path = $HTTP_SERVER_VARS['PHP_SELF'];
              
              $full_web_path = "http://" . $current_host . $current_path; 
              
              Hope that helps.

              Rory

              Promote a site that actually retains members!

              Comment

              • 3Xguru
                Confirmed User
                • Sep 2001
                • 1281

                #8
                I have seen some of the variables that PHP has using the phpself() function and I now know how to solve the problem.
                hanks to all, especialy to NotJoe
                -=Free Webmaster Tools=-

                Comment

                • Rory
                  Confirmed User
                  • Jul 2002
                  • 616

                  #9
                  http://www.php.net/manual/en/reserved.variables.php

                  Promote a site that actually retains members!

                  Comment

                  • 3Xguru
                    Confirmed User
                    • Sep 2001
                    • 1281

                    #10
                    Originally posted by Rory
                    So here is everything you need :
                    PHP Code:
                    $current_host = $_SERVER['HTTP_HOST'];
                    $current_path = $_SERVER['PHP_SELF'];
                    
                    $full_web_path = "http://" . $current_host . $current_path; 
                    
                    Now the variable $full_web_path contains the correct info. The "http://" is optional. Like I said above if your PHP < 4.1 you will need to use $HTTP_SERVER_VARS instead of $_SERVER. So this would replace if you are running an earlier version of PHP :
                    PHP Code:
                    $current_host = $HTTP_SERVER_VARS['HTTP_HOST'];
                    $current_path = $HTTP_SERVER_VARS['PHP_SELF'];
                    
                    $full_web_path = "http://" . $current_host . $current_path; 
                    
                    Hope that helps.

                    Rory
                    Thanks again. We need more helping people like you on this board.
                    -=Free Webmaster Tools=-

                    Comment

                    Working...