sagnik Posted April 6, 2017 Posted April 6, 2017 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?
wolstech Posted April 6, 2017 Posted April 6, 2017 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.
sagnik Posted April 6, 2017 Author Posted April 6, 2017 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"; ?>
wolstech Posted April 6, 2017 Posted April 6, 2017 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.
sagnik Posted April 6, 2017 Author Posted April 6, 2017 If I set a variable with the path in my config file then also I've to include the config file like you explained: <?phprequire_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?
wolstech Posted April 6, 2017 Posted April 6, 2017 If I set a variable with the path in my config file then also I've to include the config file like you explained:<?phprequire_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.
sagnik Posted April 6, 2017 Author Posted April 6, 2017 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.
wolstech Posted April 6, 2017 Posted April 6, 2017 I'm not sure if we can support that or not. Make a post over in customer service asking for it on your server and I'll see what Krydos says.
Krydos Posted April 7, 2017 Posted April 7, 2017 Why not just use $_SERVER variables? http://php.net/manual/en/reserved.variables.server.php That's where browwhatever is getting their data from most likely anyways.
sagnik Posted April 7, 2017 Author Posted April 7, 2017 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'].
Krydos Posted April 7, 2017 Posted April 7, 2017 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.
sagnik Posted April 7, 2017 Author Posted April 7, 2017 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...
wolstech Posted April 7, 2017 Posted April 7, 2017 Perhaps a library like https://github.com/piwik/device-detector/ can do what you need? That one seems to detect most browsers and operating systems, among other things.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now