iframes are being blocked by some ad blockers (as I found out). I tried to use embed and object but neither one of them works in ipads (and some iphones). So what other options do I have apart from iframe / embed / object?
You could use php or Jquery load, or even Ajax, but that is just a suggestion. I won't be able to help you code that because that is beyond my current ability. I don't know what you are using iframe for, but maybe you could replace it with a flash object instead, so that it displays what you are wanting it to display.
You can do something like this with Javascript, but it takes a little php to allow the javascript to call another domain by turning on Cross Origin Resource Sharing for that domain xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if(xhr.readystate == 4 && xhr.status == 200) { document.getElementById('displayDiv').innerHTML = xhr.responseText; } }; xhr.open('GET', 'http://myIframereplacement.com/stuff?request=data', true); xhr.send(); Code (markup): and now the PHP to allow the javascript to GET from the external domain <?php header('Access-Control-Allow-Origin: http://myIframereplacement.com'); ?> Code (markup):
My answer would be "You get NOTHING!!!" --- there's a reason we're NOT supposed to be doing that crap in the first place... If the information is on your own domain, just put it in the page normally as a part of a normal page-load, if it's not on your domain and is being nabbed by an adblock, live with it since it's probably blocking something scummy, scammy, or designed to open security holes.
Ajax won't work. I have tried it. What I can think of is canvas but implementing ad on canvas is very complicated and may violate Google terms. The simplest solution is to sell ad directly I was thinking if PHP functions like file_get_contents() can do the trick. I mean loading string from the other site and fired it with JavaScript. I've to try the idea. This may not work with Google adsense, however, and it may cause slow page load.
I found out what the culprit was. One of my folders is named "banners". Adblock plus blocks a file/folder with that name.
Are readfile and file_get_contents essentially the same? I am not using it to get a remote site / file. I am using it in the same directory. Still I was wondering which one may use less resources / cpu and which one is faster. <?php $file_contents = readfile('http://' . $_SERVER['HTTP_HOST'] . '/somefoldert/somefile.php'); print $file_contents; ?> Code (markup): <?php $file_contents= file_get_contents('http://' . $_SERVER['HTTP_HOST'] . '/somefoldert/somefile.php'); print $file_contents; ?> Code (markup):
readfile you don't need to print. It prints/echo's all by itself. THIS: readfile('http://' . $_SERVER['HTTP_HOST'] . '/somefoldert/somefile.php') Code (markup): would be the same as your second code box... well, except for ONE problem. If that separate .php is on the same domain, the code won't run it will display it's source instead... and I don't think (I could be wrong) that readfile can even read from a separate domain. Anything you load with readfile is just shown as flat text, any PHP code inside it (or any other code for that matter) will not run on the server, PERIOD! It would just send the source of that file to the browser un-run. If it's php you want to run from the same directory, that's include or require's job. ... which is why I was sitting here wondering "Why are you dicking around with frames, ajax or file_get_contents? Just include the blasted thing!". If it's in the same directory as the running program, or even the same server, why are you wasting time with all that other nonsense?
Yes, @deathshadow is right. That's the job for require or include functions. I'm not sure if file_get_contents has performance penalty or improvement. I use it to fetch encoded data. For getting data from remote site, I see it slows enough to let adblock finishes its scanning task of get rid of those ads divs. That's where a light bulb pop-up in my head. I've yet to see if my theory worked.
I would gladly use an include if I knew how to make it work independently from the rest of the script. Everything gets messed up when I try an include. With an iframe (which I ended using LOL. See the first post.) or a file_get_contents it's easy to do. What I don't like about file_get_contents it does slow the page down. Maybe when you use just one it's not noticeable, but when you have 3-4 of them you can clearly see that it's not the best way to go.
That should be an iframe to blame. It has been known for age that it slows page load down and was advice to be avoid. (This reminded me of the old day of flash days and Java applets Since you use it to hold ad placement, I don't think you have a choice for a while until someone come up with the idea how to solve this problem. Have you ever heard of PHP multi-thread? That technique should help improve your site performance significantly since it executes tasks separately and utilize all of your server CPU cores. I think that's the way to go for the moment, for serious developer, of course.
I beg to differ. I read that because file_get_contents reads a file as a string, depending on a size of that file (especially if it's a php one), it can slow a page more than an iframe. I can tell even visually that my iframes bring up content / images faster.
If that's being pulled from the same domain, and the 'include' takes "so long" there is something disastrously wrong with either what's being included itself, or the page you are trying to host it from. THOUGH, that's why advertisements are often loaded using asynchronous javascript. Again making AJAX an even better choice depending on what you are serving given you can make it wait to load the "extra" stuff until AFTER onload for the content has fired. You could even skip the AJAX and just modify the DOM directly on the fly after load. I think for any of us to REALLY say anything more that's meaningful about this, we'd need to see what page you are trying to include this extra stuff on, and what it is you are trying to include. Otherwise we're all just guessing wildly in the dark.