Drongo_III Posted April 22, 2015 Share Posted April 22, 2015 I'm currently planning out a pixel tracking PHP script. From reading around there appears to be two ways to serve a pixel back to in the request: 1) creating a 1x1 pixel image using GD library 2) sending back 200 code in the header and serving no image at all However, using GD library seems like quite an expensive way to serve a 1x1 pixel. So what I wanted to know was if I went down this route is there any advantage of using GD library over just serving a 1x1 pixel image (i.e. a 'physical' image) that's actually stored on the server? Any advice is appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/295778-pixel-tracking/ Share on other sites More sharing options...
requinix Posted April 22, 2015 Share Posted April 22, 2015 (edited) Why go through GD? 1. Make a 1x1 transparent pixel in MS Paint or whatever, save as GIF for the small size. 2. Do echo base64_encode(file_get_contents("/path/to/pixel.gif")) and copy that. 3. Paste it in code as header("Content-Type: image/gif"); echo base64_decode("base64 encoded stuff here"); Edited April 22, 2015 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/295778-pixel-tracking/#findComment-1509680 Share on other sites More sharing options...
Drongo_III Posted April 23, 2015 Author Share Posted April 23, 2015 Thanks requinix. I though gd library wasn't the best idea but you'd be surprised how many websites recommend it. I wouldnt have thought of base64 - really nice suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/295778-pixel-tracking/#findComment-1509782 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.