rtadams89 Posted December 14, 2008 Share Posted December 14, 2008 I start all of my PHP pages off with this code: <? require_once($_SERVER['DOCUMENT_ROOT'].'/includes/config.php'); ?> The "config.php" file contains (among other things) this: ob_start("ob_gzhandler"); which enables gzip compression for all my pages. I have one page on my site for which I need gzip compression OFF. I tried surrounding the gzip code in the "config.php" with an IF statement as follows: if (!isset($GET_['gzipoff'])) { ob_start("ob_gzhandler"); } then one the file for which I want gzip off, I changed the require_once line to: <? require_once($_SERVER['DOCUMENT_ROOT'].'/includes/config.php?gzipoff=1'); ?> Unfortunately this results in an error about not being able to include the file. Is it not possible to pass a variable to the included file this way? If not, is there a simple way to disable the gzip compression on just this one page? Link to comment https://forums.phpfreaks.com/topic/136880-solved-passign-get-variables-to-include-file/ Share on other sites More sharing options...
peranha Posted December 14, 2008 Share Posted December 14, 2008 From my experiance you need to set it to a variable. <?php $docroot = $_SERVER['DOCUMENT_ROOT'][ require_once($docroot/includes/config.php?gzipoff=1'); ?> Also, always start php with the full php tags as short tags may not be supported on the server. In your case right now they probably are, but if you ever move servers, they may not be. Link to comment https://forums.phpfreaks.com/topic/136880-solved-passign-get-variables-to-include-file/#findComment-714902 Share on other sites More sharing options...
PFMaBiSmAd Posted December 14, 2008 Share Posted December 14, 2008 Including/requiring a file thought the file system literally includes that code into the main file. GET parameters are not parsed on the end of the URL because that is a feature of HTTP requests and web servers, not file system requests. Just use a variable or a defined constant - $gzipoff = false; // cause the variable to be set (actual value is not important.) require_once($_SERVER['DOCUMENT_ROOT'].'/includes/config.php'); if (!isset($gzipoff'])) { ob_start("ob_gzhandler"); } Link to comment https://forums.phpfreaks.com/topic/136880-solved-passign-get-variables-to-include-file/#findComment-714908 Share on other sites More sharing options...
rtadams89 Posted December 14, 2008 Author Share Posted December 14, 2008 There was a slight syntax error in your code, but I got it to work with if (!isset($gzip_off)) { ob_start("ob_gzhandler"); } Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/136880-solved-passign-get-variables-to-include-file/#findComment-714917 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.