Search code examples
phpurlpngembedtemporary-files

How to generate random embed image url


I'm trying to hide my image url including dir path. I tried base64 but it always shows the same url, I need a different one everytime I hit refresh. I then tried to create a temporary one using tempnam, but it only adds some characters at the end of the link and don't change the dir path.

I also tried createimagefrompng but it gives me either my website with no picture, or just a picture of a white frame.

When my player goes on the page, the page generate a random number from 1 to 5 and letter A or B, go in folder "A" or "B" and search for the picture with the generated number in that folder.

The Problem is the picture url is images/A/1.png, I want it to be random so he can't use a script to refresh until he gets A/3.

And I want it to be different everytime because he could find A/3 embed url and use the script to find that embed url.

Thank you! Jessie


Solution

  • Ok managed to finally make it work!

    I'm using a mix of things I've already tried.

    So first the base64encode was great, but it always had the same url which I didn't want.

    So I searched on how create a new encoding that I could make random and found that code: https://gist.github.com/LogIN-/e451ab0e8738138bc60b

    I then generate a random key and encode the image link using that random key.

    I then call an php image using createimagefrompng and put the key and encoded image link in the php url (www.example.com/image.php?encoded=jsnda9d9832rm&key=emd39023)

    And then in that php decode the url using the key and show the image ^^

    Hope it can helps other, also if you see something I could change so my code will be lighter or have better performance please don't hesitate :)