Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Hiding an image URL...

Mamonos
 Share

Go to solution Solved by colonel_mortis,

A simple solution would be to have another PHP file on your server that proxies the image. That script would look something like

<?php

$webcamImageUrl = "http://111.111.111.111/snapshot.jpeg";

$curlRequest = curl_init();
curl_setopt($curlRequest, CURLOPT_URL, $webcamImageUrl);
curl_setopt($curlRequest, CURLOPT_HEADER, false); // Don't include the response headers in the result
curl_setopt($curlRequest, CURLOPT_RETURNTRANSFER, true); // Return the body of the requested resource
curl_setopt($curlRequest, CURLOPT_TIMEOUT, 10); // Timeout if it takes > 10s

$imageData = curl_exec($curlRequest);
if (curl_error($curlRequest)) {
  http_response_code(500);
  echo "Error: " . curl_error($curlRequest);
  exit;
}

header("Content-Type: " . curl_getinfo($curlRequest, CURLINFO_CONTENT_TYPE));
echo $imageData;

That could be improved by caching the image on disk so it doesn't get requested too often.

 

PHP isn't the ideal language for this because it has to load the whole image into memory before it can send it back to the user, but it should be good enough for your use case.

Hello,

 

I've been trying to find a solution to this...

 

I have a weather webcam connected to a router and I can retrieve a *.jpeg snapshot from the router public ip address, like

 

111.111.111.111/snapshot.jpeg

 

I have now created an HTML page on my website to display the snapshot, but I would like to somehow hide the public IP.

 

It seems it's not possible to hide it using HTML, I've been thinking of using data-uri but this is not suitable since I want the user to be able to refresh the page and see a new image.

 

So I've been thinking/trying some kind of workaround but with no real solution due to my limited knowledge

 

These are the possibilities I've been thinking to

1) Use the .htaccess file to somehow "proxy" or "mask" the webcam IP (how?)

2) Have a script or something that "saves the image as" once every minute on my FTP folder (unfortunately my webcam can't to this natively and I have no idea how to do it)

 

Can someone help me with this? Or any other ideas?

 

 

Thanks

Link to comment
Share on other sites

Link to post
Share on other sites

You can mount FTP as a local file system using FUSE, if your server is running Linux https://wiki.archlinux.org/index.php/CurlFtpFS . So you can mount 111.111.111.111 in say, /var/www/public_html/router (or whatever cute name you want) and access it via http(s)://yoursite.com/router/snapshot.jpeg .

 

If you're not running Linux or you don't have direct access to the host machine things get more complicated.

The Eight Fallacies of Distributed Computing

Essentially everyone, when they first build a distributed application, makes the following eight assumptions. All prove to be false in the long run and all cause big trouble and painful learning experiences.

  1. The network is reliable
  2. Latency is zero
  3. Bandwidth is infinite
  4. The network is secure
  5. Topology doesn’t change
  6. There is one administrator
  7. Transport cost is zero
  8. The network is homogeneous

        — Peter Deutsch

Link to comment
Share on other sites

Link to post
Share on other sites

I see. Well what you're trying to do depends a lot on the tech stack on the server as that's where you're going to have to do it: a client will have to know the IP of your router in order to fetch the image for itself.

 

If you're running PHP, for example, it might be most reasonable to have a script to fetch the image and serve it (http(s)://yoursite.com/router_data.php?path=snapshot.jpeg), but I have no idea how to write that, since I don't do PHP.

The Eight Fallacies of Distributed Computing

Essentially everyone, when they first build a distributed application, makes the following eight assumptions. All prove to be false in the long run and all cause big trouble and painful learning experiences.

  1. The network is reliable
  2. Latency is zero
  3. Bandwidth is infinite
  4. The network is secure
  5. Topology doesn’t change
  6. There is one administrator
  7. Transport cost is zero
  8. The network is homogeneous

        — Peter Deutsch

Link to comment
Share on other sites

Link to post
Share on other sites

You could always download it in javascript then convert it to base64 and make that the source of the image. You will be able to see the image url in the sources tab in the developer screen, but it will hide it from people just looking at the inspect element

 

What kind of server do you run? You could always do a PHP rerouting script or a python rerouting script

Link to comment
Share on other sites

Link to post
Share on other sites

A simple solution would be to have another PHP file on your server that proxies the image. That script would look something like

<?php

$webcamImageUrl = "http://111.111.111.111/snapshot.jpeg";

$curlRequest = curl_init();
curl_setopt($curlRequest, CURLOPT_URL, $webcamImageUrl);
curl_setopt($curlRequest, CURLOPT_HEADER, false); // Don't include the response headers in the result
curl_setopt($curlRequest, CURLOPT_RETURNTRANSFER, true); // Return the body of the requested resource
curl_setopt($curlRequest, CURLOPT_TIMEOUT, 10); // Timeout if it takes > 10s

$imageData = curl_exec($curlRequest);
if (curl_error($curlRequest)) {
  http_response_code(500);
  echo "Error: " . curl_error($curlRequest);
  exit;
}

header("Content-Type: " . curl_getinfo($curlRequest, CURLINFO_CONTENT_TYPE));
echo $imageData;

That could be improved by caching the image on disk so it doesn't get requested too often.

 

PHP isn't the ideal language for this because it has to load the whole image into memory before it can send it back to the user, but it should be good enough for your use case.

HTTP/2 203

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

Newegg

×