Hi all PHP experts, I have a little bit problem to use require_once. I have a file.php in the: root/sub/file.php. I used <?php require_once('sub/file.php') ?> from mainpage (index.php) and working fine on Firefox, Opera and IE(9) but not working on Chrome and Safari. Trying to use include, but still got working. What's wrong with that code? Is it depend on the browser platform? Thank you for your help. Regards
When you state "not working" what do you mean? Is there an error message? Is something not appearing that should? Try to be a bit more descriptive. (Also, the PHP is processed server side, so it's not as simple as stating it doesn't work in x browser.) What is supposed to be produced by this file? Is the require_once (or the contents of the file) triggered upon a condition?
you're correct, ryan .. there is not something appearing that should. No error message but it seems stop loading without any results. Hmmm .. or may be caused by js .. I used js at <head> section. But why not working only on chrome and safari ? I use default setting of them. I've spent much time to get luck but have not yet successful
There's probably a problem in your Javascript or HTML. Some errors cause some browsers to stop parsing, while other browsers ignore that particular error. (Firefox ignores most errors, IE tends to stop at any Javascript or HTML error.) You should be debugging your code. Make sure that it gets past the require() statement. BTW, the only difference between include() and require() is that if require() fails, the code stops. If include() fails the code will continue on to the next line (and probably die further down the line, because the included function isn't there).
Have you checked your server logs for any PHP errors? You might not be seeing an error due to how PHP has been configured (check that display_errors is on and what level error_reporting is set to - there are various ways to set both, research and choose what you prefer/is best for your environment). I assume you also checked the HTML source and not just the rendered output? It's hard to give specific advice as I don't know what your code is doing. Maybe it's worth checking out Eclipse and XDebug to help you debug your code? (There are also other PHP debuggers out there, though, if you don't like it.) Good luck!
Also, make sure those browsers aren't caching or something. require/include are executed server side and are independent of any browser. I've seen in the past where IE would not release a cached page even after hitting refresh a bunch of times.
Ctrl-F5 should do it. If not, close IE and open it again. If it still doesn't work (and you have it set to refresh on every visit to the site), you know one more reason for all those punctuation marks in front of the letters 'IE'.
There is such a logic disconnect in the opening post I had to read it twice.... since require_once runs server side, there is ABSOLUTELY NOTHING a browser could do that would effect if it works or not. The problem must be in the output of said includes. As mentioned, some bit of invalid or malformed code is probably stopping those browsers dead in their tracks... something like multiple headers, multiple doctypes, unclosed comment that's assumed closed, unclosed tag that is debugged differently across browsers, etc, etc... Do you have an example of the page in question? Without seeing your code or it's output anything you are told in this thread is a wild guess at best. Literally without showing us the full code you are using, you've tread into the land of "and this is why we can't help you". Though if it's anything like that dressesfair website in your siggy, being a train wreck of framesets, endless inlined scripting for nothing, and general laundry list of 'how not to build a website' -- I'd be shocked if it worked the same across any browsers. (and that's without mentioning it reeking of "WCAG, what's that?" design)