bglinkerman Posted January 3, 2009 Share Posted January 3, 2009 I have several pages of PHP code that all have about 100 lines of the same code on each page that contains a list of variables. I would like to set it up so that the pages pull this data from an external file so that if I need to make an update to the variables I don't have to change the variable on each page. For example: This PHP program is designed to aid in an emergency failover. Basically, the first page asks you to select the current live site and the desired failover site. These variables are then past to the next page in the form of a GET command. Then at the top of each page throughout the rest of the site a few "if" statments are run against the two GET variables ("live" and "dr") and then dynamically sets a number of variables (which include ip addresses and hostnames). Once the user makes it to the bottom of this page they are presented with several options on how they want to proceed. Each link is dynamically generated to forward the "live" and "dr" variable to the next page which has the same code at the top to set the correct variables. It works great as is but if an IP address or hostname changes I need to modify each page. I'd like to create an external page that has these first 100 lines of code or so and then have one or two lines of code at the beginning of each page that tells the php engine to link to the external file and insert that 100 lines of code to the top of the page and then continue processing. Below is a small sample of what the code looks like: <?php # Retreive Live and DR Site Information from Form Submission $liveSite = $_GET['live']; $drSite = $_GET['dr']; # Set Current Live Site Variables if ($liveSite == "A") { $sitePrimary = "Virginia"; $siteAbbrPrimary = "va"; $db1aPrimary = "123.456.789.123 db1a"; $db1bPrimary = "123.456.789.123 db1b"; $gate1Primary = "123.456.789.123 gate1"; $gate2Primary = "123.456.789.123 gate2"; } if ($liveSite == "B") { $sitePrimary = "Texas"; $siteAbbrPrimary = "tx"; $db1aPrimary = "123.456.789.123 db1a-dr"; $db1bPrimary = "123.456.789.123 db1b-dr "; $gate1Primary = "123.456.789.123 gate1-dr"; $gate2Primary = "123.456.789.123 gate2-dr"; } # Set DR/Alternate Site Variables if ($drSite == "A") { $siteAlternate = "Virginia"; $siteAbbrAlternate = "va"; $db1aAlternate = "172.28.253.78 db1a"; $db1bAlternate = "172.28.253.34 db1b"; $gate1Alternate = "123.456.789.123 gate1"; $gate2Alternate = "123.456.789.123 gate2"; } if ($drSite == "B") { $siteAlternate = "Texas"; $siteAbbrAlternate = "tx"; $db1aAlternate = "123.456.789.123 db1a-dr"; $db1bAlternate = "123.456.789.123 db1b-dr"; $gate1Alternate = "123.456.789.123 gate1-dr"; $gate2Alternate = "123.456.789.123 gate2-dr"; } ?> ....................REST OF CODE...................... I'd like it to be like this: <?php # Retreive Live and DR Site Information from Form Submission $liveSite = $_GET['live']; $drSite = $_GET['dr']; # Set Site Variables "readexternalfile(hosts)" ?> ....................REST OF CODE...................... Link to comment https://forums.phpfreaks.com/topic/139317-import-external-php-codeconfig-file/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 3, 2009 Share Posted January 3, 2009 require Link to comment https://forums.phpfreaks.com/topic/139317-import-external-php-codeconfig-file/#findComment-728671 Share on other sites More sharing options...
bglinkerman Posted January 3, 2009 Author Share Posted January 3, 2009 Cool, I guess that was easy enough. I read the PHP man page for that and it seems to be exactly what I'm looking for. Thanks so much! Link to comment https://forums.phpfreaks.com/topic/139317-import-external-php-codeconfig-file/#findComment-728685 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.