PHP Tactics For Finding The URL Being Browsed

PHP Tactics For Finding The URL Being Browsed

The current URL is a very valuable piece of information to PHP developers, who will need to shape services and requests around what the visitor is currently browsing. You will be overjoyed to see that the latest version of PHP includes phenomenal support for doing this with relative ease.

PHP uses what are called server variables to access different pieces of information about the current HTTP request, as well as a myriad of other miscellaneous server information that can come in quite handy. It should be noted before we get into the specifics of server variables that some information can be spoofed or faked- so be carefully when trusting HTTP information.

To easily find the current domain that the user is browsing, you can use the server variable named HTTP_HOST. This server variable is useful for building links to different parts of your website, or for using remote files for inclusion. This variable is going to allow you to call the domain in the format of “YourName.com”; you will have to concatenate onto this to properly build any links or pass this data onto other functions.

Because the HTTP_HOST script variable can’t tell you the actual path to the script, you will need a different variable to be more precise in this respect. The best course of action is to make use of the SCRIPT_NAME variable, which serves exactly this purpose.

Perhaps one of the most useful of all server variables is the QUERY_STRING variable. This variable allows us to find the query string that lies within the URL, which comes directly after the ternary symbol. This allows developers to pass data from one script to another flawlessly. Just be sure to encode your URLs while doing this, or you may create security holes that will prove to be quite disastrous to your website or database.

A great way to get the current URL even if you are using rewriting on your domain is to use the server variable REQUEST_URI. This variable will ignore any rewriting information that the “.htaccess” file tells the server to perform, and instead report the actual name of the running script. This is must-know tool for anyone who makes use of the Mod Rewrite tool.

Closing Comments

As another warning, consider the many security flaws you can put into your application by relying on server variables without regards to your application’s health. Always be sure to sanitize all input when interacting with your database and query strings, and remember HTTP information isn’t always trustworthy.

About the Author: Learn more on php find url in string and the current url in php.

Watch the video related to Php Scripts

Help answer the question about Php Scripts

I need to create a php script that will upload a video file onto the server?
I've already created all user interfaced pages including the upload form and the page to show the video.I've created the database where the video file info will be stored.The website and database resides on the main server. I need a solution and script to upload a video file which is to be compressed and stored in the database. The script should be in php and mysql

About Author

Learn more on php find url in string and the current url in php. About the Author:

wikishoes.com provides a great variety of jordan shoes, get more information and specifications about these sneakers, plz visit us at http://www.wikishoes.com

18 Responses to “PHP Tactics For Finding The URL Being Browsed”

  1. champ0y says:

    You’re really good man. You’ve got excellent talent.

  2. monkeymanbob says:

    Nice work, you did pretty good.

  3. warah110 says:

    Perfect.

  4. Atticus says:

    You can use a menu maker if you're not sure how to code something on your own. There are a gazillion of them out there and many are even free. Pick one that suits you…

    http://www.google.com/search?source=ig&hl=en&rlz=&q=web+menu+maker&btnG=Google+Search

  5. relientkfan153 says:

    The "something" can be accessed very easily with PHP. If you have a web page address that looks like this:

    index.php? month=september&name=smith&age=24

    Then you can access those values in PHP like this:

    <?php
    echo $_GET('month');
    echo $_GET('name');
    echo $_GET('age');
    ?>

    This will print septembersmith24.

    As for accessing a text file, that's easy too:

    <?php
    $text = file_get_contents( 'textfile.txt' );
    echo $text;
    ?>

    This will read the entire contents of the file textfile.txt into the variable $text, and then print it out for you.

    You can also access many databases with PHP, I highly recommend you use MySQL. It's a bit too complicated to describe here, though. There are some good references made to good books by folks above. The "Teach Yourself" series is great.

  6. Ars Magicana Arcanum says:

    Windows XP PRO has functionality for running a web server built in

    IIS is an option, however, under a "Default" installation of XP Pro, it might not be installed

    Control panel – > add / remove programs -> Add Remove Windows COmponents – Check "Internet Information Services"

    You could also look @ apache as has been mentioned, however, IIS is PART of windows.

  7. virgocrabtiger373 says:

    http://www.phpfreaks.com/tutorial_cat/8/Basics-&-Beginner-Tutorials.php

  8. Simplicated says:

    If you have sensitive files that should be accessible only by scripts, put them somewhere on the server other than the web root. Your scripts will still be able to access them, but nobody can pull them off the web.

    /
    – /htdocs
    – — /www.site.com
    – /securedocs

  9. Forbidia says:

    Brilliant Willy, Just Brilliant =D

  10. superchode20164 says:

    amazing! Willy teach me how to paint like you!

  11. ampersand1 says:

    http://www.phpfreaks.com

    If you are ready invest: Get Larry Ullman: 'PHP …" Nice book

  12. lidiabarbarita says:

    Very nice!!

  13. avb17018411 says:

    woww that’s really relax and beatiful soung .good picture of jhony depp !

  14. Mike says:

    Hi,

    Best Site to Learn PHP http://www.w3schools.com/php/default.asp

    I know this Answer Will solve your problem. Do one thing visit http://www.zakhas.com/Forum be a member first and Download 1800 Industry standard PHP Projects and source codes. Directly without any interrupting. Follow below link for direct access to the download link.http://www.zakhas.com/Forum/ViewThread.asp?Thread=161&Forum=26
    Definitly it will solve your problem. Download it BE Quick.

    Or you can try this sites below

    http://www.planetsourcecodes.com

    or

    http://www.scriptswave.com/free/scripts/php_scripts/9.html

    If you find this answer is best then you can choose it as best answer.

  15. Jeremy H says:

    I don't think there is such a thing as a PHP emulator, and I don't know why you'd need one. It's likely that you either didn't install PHP and apache correctly or you aren't using it right.

    Use XAMPP to install PHP and apache. It will also include MySQL and phpMyAdmin (which you will need sooner or later) and some other good stuff too. It's much easier than trying to configure PHP and apache by hand. Best of all, it's all configured to run together immediately. XAMPP and all of its components are free and open source.
    http://www.apachefriends.org/en/xampp.html

    Once you've got a web server, you need to turn it on (that's not automatic.) There's a nice control panel that makes this easy with XAMPP. PHP files will only work if they're in a specific subdirectory (usually htdocs in the apache directory structure) Also, you can't just load a PHP file into the browser the same way you do an HTML file. Instead, you need to point the browser to
    http://localhost/yourFileName.php

    PHP is called by the server, so if you use a mechanism (like the file:// directive) that bypasses the server, your PHP programs won't run.

  16. Faithless863 says:

    hm i couldn’t tell the difference between photograph and painting comparing the final resault.

    This is sick

  17. Sameer A says:

    http://www.elite.ro/free-hosting-php/
    http://www.awardspace.com/
    http://www.free-phphosts.com/
    http://www.freehostia.com/free_hosting.html

    Really what you need to run php is some one who also offers a sql database these do but I dont get the website builder thing?
    if your messing around with php why would you need a WYSIWYG builder?

  18. TheTroubadourMusic says:

    :O

    :O

    :O

    how is this not a real photo?

Leave a Reply