PHP 'require' not working in all browsers?


I have a forum, based on SMF, as this one is. The forum is in the public_html root. Members are controlled by the SSI.php file and not htaccess.
There is a page created by php that I only wish logged in members to be able to view.
I was advised to include the following code right at the top of the php file, before anything else:

<?PHP require('/home/user/public_html/'); if ($user_info['is_guest']) $_SESSION[''] = ''; is_not_guest(); The rest of the code produces a form page which collects information to a database. The 'require' works fine in IE8 or 9; Safari; and Firefox, users are referred to the log in screen; but not in Opera or Google Chrome, where the page is immediately displayed. The 'require' path is for cPanel. No doubt a schoolboy error on my part, I would be grateful for some advice. Regards Paul

The ‘require’ as well as any other PHP directives does not depend on your browser. PHP is a server side language, it can return to your browser only HTML/CSS/javascript generated code, as well as http headers (cookies, session variables, etc.) It is likely your problem is in authentication code. Check what headers info is sent to your browser from your site, while you’re logging in and when you navigate to this your page.

Thank you for your advice. I have looked at the headers produced in the pages produced, but can’t find the issue as I really have no idea what I might be looking for. I’ve also done some reading up, and run the following:

<?php phpinfo(); ?>

which shows my server has PHP v5.2.15, and I assume that is all ok.

I then ran the <?php phpinfo(); ?> with the ‘require’:

<?php require('/home/user/public_html/'); if ($user_info['is_guest']) $_SESSION[''] = ''; is_not_guest(); phpinfo(); ?>

but I get exactly the same results; i.e. it works fine except in Chrome and Opera.

Should I be intercepting the header information before the browser interprets it, and if so how? Or is there a defect in my ‘require’ syntax?

Apologies, but I am very new at this. :slight_smile:



Sponsor our Newsletter | Privacy Policy | Terms of Service