Jump to content

Php Auto Include Page Header And Footer


Recommended Posts

I've did it. I've automatically included header.php and footer.php using php.ini directive "auto_prepend_file" & "auto_append_file" in localhost with HTTPD. Now my question is can I do it in HelioHost in anyhow? Like using .htaccess, php.user.ini or any other things. And one more thing, I need to use "browscap", can you please add "full_php_browscap.ini" in the php.ini or allow me to do so by any method?

Link to comment
Share on other sites

This is considered bad practice for exactly the reason you're experiencing...it requires modifying system properties. The other issue is that by doing it that way, it affects the entire server instead of one program.

 

The proper way to do this is to just do use an include() or require() where the header and footer belong, or more often than not just call a function that echos the content from the database.

Link to comment
Share on other sites

I've 3 domains which can access the folder "mobile". Roots for the domains will be different so the path to reach the folder "mobile" from different domains will be different. Document Roots for the domains are: "sgnetworks.cu.cc": "/home/sgn/public_html", "netmate.cu.cc": "/home/sgn/public_html/nm/public_html", "m.netmate.cu.cc": "/home/sgn/public_html/nm/public_html/mobile". So I've to use this block of code to include header and footer:

<?php
if($_SERVER['DOCUMENT_ROOT'] == "/home/sgn/public_html/nm/public_html/mobile"){
$docRoot = $_SERVER['DOCUMENT_ROOT'];
} else if($_SERVER['DOCUMENT_ROOT'] == "/home/sgn/public_html/nm/public_html"){
$docRoot = $_SERVER['DOCUMENT_ROOT']."/mobile";
} else if($_SERVER['DOCUMENT_ROOT'] == "/home/sgn/public_html"){
$docRoot = $_SERVER['DOCUMENT_ROOT']."/nm/public_html/mobile";
}
require_once $docRoot."/global/header.php";
?>
Link to comment
Share on other sites

Seeing all of these should ultimately point to the same file, forget all the fancy logic and just use an absolute path. Includes are based on path from filesystem root, not web/document root, so the absolute path to the file would work regardless of which domain is used.

 

If I'm following the code correctly, you should be able to just replace all of that with:

<?php
require_once('/home/sgn/public_html/nm/public_html/mobile/global/header.php');
?>

If you want to be nice about making it editable/movable later, set a variable containing the "/home/sgn/public_html/nm/public_html/mobile/global/" part in your config file (I'd personally just do it in the same one that has my database settings) so you can edit that path later if you need to move the scripts, without finding all the require_once() statements and editing them.

Link to comment
Share on other sites

If I set a variable with the path in my config file then also I've to include the config file like you explained:

<?php

require_once('/home/sgn/public_html/nm/public_html/mobile/global/header.php');

?>

So what will be the advantage of storing the value to a variable??

And what about browscap? Can I use browscap? If yes then how? If not then, what is an alternative of browscap?

Link to comment
Share on other sites

If I set a variable with the path in my config file then also I've to include the config file like you explained:

<?php

require_once('/home/sgn/public_html/nm/public_html/mobile/global/header.php');

?>

So what will be the advantage of storing the value to a variable??

And what about browscap? Can I use browscap? If yes then how? If not then, what is an alternative of browscap?

*facepalm* This is what I get for posting before my coffee (it's not even 8am here yet). Yeah, the variable would need to be set in the same file. Using it still means only one edit per file vs. editing every include/require though.

 

Another thing to consider is that relative paths and .. will work too (e.g. require("../includes/file.php") means "go up one folder, then go into the includes folder, then include file.php in there), so you might want to explore possibly using this instead (this is how I do it).

 

I have no idea what browscap is, so no comment on that.

Link to comment
Share on other sites

Ok thanks, I've followed you.

 

Browscap provides the details of user's browser, device & platform. In fact, the name, version,build manufacturer of the browser and platform/os and name, model, date of manufacture, etc of device which is the user using. full_php_browscap.ini takes around 55.56MB size.

 

Browscap need to be set as a directive in php.ini, like,

 

[browscap]
browscap = "C:\php\extras\full_php_browscap.ini"
If you add full_php_browscap.ini directive, it will be a great help, because I have used it in my registration and login page. If it cannot be added, then I have to change my whole registration and login related files.
Link to comment
Share on other sites

But, $_SERVER doesn't provide user's device & platform details easily, I've to do too much coding to extract the details from $_SERVER['HTTP_USER_AGENT'].

Link to comment
Share on other sites

I read about your browscap and most people agree it's a horrible bloated slow monstrosity, and at 56mb I'm going to have to agree. There is no way I'm going to add 56mb of .ini to Johnny's existing 37k php.ini. This doesn't just affect your account, but rather all of the thousands of accounts on Johnny that use php. I can't even imagine how much memory that would use.

 

This guy http://stackoverflow.com/questions/12067641/get-browser-slowing-down-page-load-any-alternative reports that calling ONE browscap function results in at least 5 seconds of additional runtime on a single php script. That's pretty ridiculous.

Link to comment
Share on other sites

Ohh, I didn't knew that.. Well if not browscap, then is there any PHP library which can provide all of this??? I've searched Google, but didn't find anything...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...