Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1081245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:08:40+00:00 2026-05-16T22:08:40+00:00

I am playing with my little PHP project right now and I am struck

  • 0

I am playing with my little PHP project right now and I am struck with a question about how I should approach the image handling. As far as I know, it’s either you host the image in your server or let the user provide the link. Given my application is on a shared hosting site, which one better? What are the risks?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:08:41+00:00Added an answer on May 16, 2026 at 10:08 pm

    User provided

    • You need to make sure the link is valid
    • You need to check the content of the link to confirm its an image
    • You need to be able to check the image on every load
    • You have to build your html to check the image is still available.
    • you would also have to confirm that the location of the image is a trusted location
    • if the image is not on a HTTPS Server and you are, then you can cause issues with browsers.

    Self Hosted Image

    • You can make sure that the image is of the correct format.
    • You need to watch out for exploits such as GIF Exploit
    • You can manipulate the image with PHP Dynamically
    • You can check and validate sizes of images and store on file-system or DB
    • Requires more bandwidth
    • If images are dynamic then they can cause high CPU

    I would suggest that you go for self hosted image, OR host images on another data centre such as an image host with an open API.

    If you your worried about bandwidth then you can create an image upload system that upon upload it uses an image host API to send the image to an external source and then store the image id in the database along with post/user/entity.

    Stack Overflow uses the ImgUr for there images,SO has already thought about what your thinking of and have chosen to store externally but upload locally, ImgUR returns data that can be stored, Example below:

    <images>
        <image>
            <name>imgur</name>
            <title/>
            <caption/>
            <hash>UrTHG</hash>
            <deletehash>bzEkpCdHPL22Hlp</deletehash>
            <datetime>2010-08-14 03:39:23</datetime>
            <type>image/gif</type>
            <animated>false</animated>
            <width>314</width>
            <height>115</height>
            <size>4413</size>
            <views>0</views>
            <bandwidth>0</bandwidth>
        </image>
        <links>
            <original>http://imgur.com/UrTHG.gif</original>
            <imgur_page>http://imgur.com/UrTHG</imgur_page>
            <delete_page>http://imgur.com/delete/bzEkpCdHPL22Hlp</delete_page>
            <small_square>http://imgur.com/UrTHGs.jpg</small_square>
            <large_thumbnail>http://imgur.com/UrTHGl.jpg</large_thumbnail>
        </links>
    </images>
    

    This is great because, thumbnails such as small_square,large_thumbnail etc are pre-generated along with meta data such as size,width,height, views etc.

    If your worried about CPU usage and server-load then you should revert to the section above regarding external data storage.

    If your worried about CPU then you can manipulate the image via GD Libraries and then store a cached version on file-system, update over intervals if need me.

    Another down pointer to having user linked images is that when the image is it can be a dynamic image and loggin user data such as what pages that suer is visiting, this one if the main reasons that when your on Facebook and you embed an entity such as a blog post, the images are downloaded and stored on Facebook’s CDN, so that outside sources cant tell what and where an IP is.

    This should help you decide.


    As there has been some discussion about the risk of XSS, i thought i would clear something up a little.

    If you choose to allow the user to give you a link to an image you would have to validate the image and not so much the content, the reason why this has to be done is because lets say the user entered the following image location.

     &#14;  javascript:alert('XSS');
    

    If you do not sanitize via PHP with functions like htmlentities() and HTML Purifier library, after you store the above string in your database, when a user attempts to visit the page it would render like so:

    <IMG SRC=" &#14;  javascript:alert('XSS');">
    

    So that every time the page renders you get a dialog box stating XSS, thi is called an XSS Atack, the atack then cauld add another image “url” / “code” that sends certain data such as SESSION ID’s to another site that automatically goes to your site and collects data under that ID.

    if an attacker entered the following url http://attacker.com/evil.js then the rendered content would be like so:

    <IMG SRC="http://attacker.com/evil.js">
    

    As this is an image tag then evil.js would not be processed as javascript, because thats not how the Document Object Model is built, this would be safe to users.

    Links on Vulnerabilities

    • CSRF
    • XSS Examples
    • XSS Wiki
    • Windows Metafile Vuln
    • Cross Zone Scripting
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm playing a little bit with WML with PHP, then I want to know
I am playing a little bit with htaccess to know apache with xampp. I
I’m just playing about with the data from a little Garmin GPS thingy I
I'm playing and trying to learn a little more about AJAX in MVC. Currently,
After a little testing/scripting/playing with PHP 5.3 PHAR archives, I discovered some problems. glob
I have been playing with CouchDB and CouchApp for a little while now. I
I'm playing around with Project Euler's Problem 220 , and I'm a little confused
I'm playing a little bit with the new StackOverflow API . Unfortunately, my JSON
Was playing around a little bit with the TimeSpan class and I started wondering
I'm playing around a little with Python and curses. When I run import time

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.