Search code examples
phpmysqlpostimgur

PHP Image display using POST URL


The popular image hosting site Imgur is great and I'm new to PHP. I'm just wondering how they manage to get an image to display in the page when entering a URL such as:

https://i.sstatic.net/PfUDg.jpg

How does the script know to display a certain image from yjg8v? Are they using $_SERVER['HTTP_HOST']?

Newbie here, not trying to be spoon fed, willing to read and study, just cant find much help on the internet about it.


Solution

  • Sites like imgur.com often "clean URLs" instead of traditional URLs with parameters.

    Before clean URLs, you would see something like:

    imgur.com/image.php?id=yjg8v
    

    In your script, you can access the parameter via

    $_GET['id'];
    

    To produce clean URLs, you can use mod_rewrite in Apache (or a similar technology in your chosen web server) to map '/gallery/yjg8v' to '/image.php?id=yjg8v'.

    You can find additional mod_rewrite information here.