hideous Posted June 2, 2008 Share Posted June 2, 2008 I do not know much at all about PHP except for the include function. I was in the process of putting a site together when my host SteadFast went from a PHP 4 w/apache (<-- I beleive Apache) server to a PHP 5 w/ Litespeed server. I used to write my includes as <?php include("http://mysite.com/header.html"); ?> well after the upgrade these stopped working. I messed around with them based on the onscreen error messages I was getting and by solutions found via Google and finally came to realize that this worked... <?php include ("/hsphere/local/home/myaccountname/mysite.com/header.html"); ?> I also changed my .htaccess file which used to read only AddHandler application/x-httpd-php htm html on the old server to... AddHandler php5-script htm html php AddType text/html php on the new server. I have a few questions about this though. 1. Why did I even need to change it what about PHP 5 caused the old method not to work. 2. What do the lines in my .htaccess actually do ? I found that they were a solution but I have not read of anyone that explains why it works and what the lines are actually doing. 3. When I was looking for solutions I read that PHP 5 used relative paths for example... <?php include ("header.html"); ?> when I tried it I got the error message that led me to add the... /hsphere/local/home/myaccountname/mysite.com/ which ended up working but no ones solution called for doing that WHY ? How is it that other people that asked the question were told to start at thier personal sites root and I have to use the root all the way back to my host company ? 4. Is any of the changes I made a security risk or do they slow things down in any way ? Is there a way to get the same effect and be more efficient in speed security etc ? 5. What is the difference between Apache and Litespeed and is this playing any part in this ? 6. I have read there is a way to alter my .htaccess file to allow my to drop the /hsphere/local/home/myaccountname/mysite.com/ above and make my includes only <?php include ("header.html"); ?> is it true is there any ill effects to doing this ? Quote Link to comment https://forums.phpfreaks.com/topic/108333-php-4-to-php-5-upgrade-problems-wincludes/ Share on other sites More sharing options...
DyslexicDog Posted June 2, 2008 Share Posted June 2, 2008 1. Most likely it's the way the server was configured. 2. The lines in your .htaccess file tell the apache server to pass the .php and .html files over to php for processing. 3. Using relative paths works just fine. If your header.html was in the same folder as your script that has the include it should have worked. ie. My website has a index.php file in the web root directory. www.mysite.com/index.php. The index.php file incudes some documents that are stored in another directory called includes. When I write my include statement it looks like this. <?php include("includes/somefile.php"); ?> 4. The simple changes you have made shouldn't make that much of a difference. 5. Litespeed is supposed to be interchangeable with apache but a lot faster. It looks like it maybe a fork of apache. 6. You can change your path statement to allow you to do something like that but it has the possibility of greatly slowing performance. Quote Link to comment https://forums.phpfreaks.com/topic/108333-php-4-to-php-5-upgrade-problems-wincludes/#findComment-555497 Share on other sites More sharing options...
hideous Posted June 3, 2008 Author Share Posted June 3, 2008 I asked this question on another forums as well and was told in responce to number 6 that I could do <?php include $_SERVER['DOCUMENT_ROOT'] . '/header.html'; ?> in the document itself or i could do the following in a .htaccess file php_value include_path /hsphere/local/home/myaccountname/mysite.com/include/ Can anyone tell me the difference between them ? PROS and CONS ? TIA Quote Link to comment https://forums.phpfreaks.com/topic/108333-php-4-to-php-5-upgrade-problems-wincludes/#findComment-556761 Share on other sites More sharing options...
hideous Posted June 3, 2008 Author Share Posted June 3, 2008 one bump TIA Quote Link to comment https://forums.phpfreaks.com/topic/108333-php-4-to-php-5-upgrade-problems-wincludes/#findComment-557027 Share on other sites More sharing options...
DyslexicDog Posted June 3, 2008 Share Posted June 3, 2008 The one supplied by the other web forum specifically states which folder to look in for the header.html file. The second solution changes the path statement, any time you run an include that is relative, your path statement would be searched. The more entires in your path statement, the more your server has to look around to find the files. On a busy website that second solution could bring a server to it's knees. Quote Link to comment https://forums.phpfreaks.com/topic/108333-php-4-to-php-5-upgrade-problems-wincludes/#findComment-557031 Share on other sites More sharing options...
chronister Posted June 4, 2008 Share Posted June 4, 2008 You will save a lot of headache if you get in the habit of doing includes as <?php include($_SERVER['DOCUMENT_ROOT'].'/path/to/include.php'); ?> I used to fight with the paths of includes, but discovered this little gem and no more include problems.... the $_SERVER['DOCUMENT_ROOT'] is the superglobal variable for /hsphere/local/home/myaccountname/mysite.com/ It will start at your site's root directory which in the above example is mysite.com Nate Quote Link to comment https://forums.phpfreaks.com/topic/108333-php-4-to-php-5-upgrade-problems-wincludes/#findComment-557046 Share on other sites More sharing options...
hideous Posted June 4, 2008 Author Share Posted June 4, 2008 one last question I was reading a little more about this method <?php include($_SERVER['DOCUMENT_ROOT'].'/header.html'); ?> and found some people do it with quotes like <?php include($_SERVER['DOCUMENT_ROOT']."/header.html"); ?> and some people don't use the ( and ) like <?php include($_SERVER['DOCUMENT_ROOT'].'/header.html'); ?> and some people put spaces in places or additioanl spaces. Since I can't bold a space I will use the * to signify <?php include*($_SERVER['DOCUMENT_ROOT']*.*'/header.html'); ?> So my question is first and foremost which is the proper syntax. And secondly, what do the differences actually change ? TIA Quote Link to comment https://forums.phpfreaks.com/topic/108333-php-4-to-php-5-upgrade-problems-wincludes/#findComment-557260 Share on other sites More sharing options...
hideous Posted June 4, 2008 Author Share Posted June 4, 2008 bump give the day shift a chance to look thanks all Quote Link to comment https://forums.phpfreaks.com/topic/108333-php-4-to-php-5-upgrade-problems-wincludes/#findComment-557647 Share on other sites More sharing options...
discomatt Posted June 4, 2008 Share Posted June 4, 2008 That's all preference... IMO, it's good practise to use brackets ( ) around all functions as well as statements ( statements are special 'functions' that don't require brackets... echo is an example of one, as well as include ) You're right regardless of the way you chose. Single quotes and double quotes are preference as well... though there is a significant difference in the way they work. read here http://php.net/types.string The spaces between the concatenation operators ('.') and variables is also all preference. I like to use spaces for better readability... as something like this include( $_SERVER['DOCUMENT_ROOT'].'/images/'.$imgCategory.'/full_res/'.$imgId.'.php' ); can be quite hectic. This is much easier to follow for my eyes at least include( $_SERVER['DOCUMENT_ROOT'] .'/images/'. $imgCategory .'/full_res/'. $imgId. '.php' ); Or even this include( "{$_SERVER['DOCUMENT_ROOT']}/images/{$imgCategory}/full_res/{$imgId}.php" ); Quote Link to comment https://forums.phpfreaks.com/topic/108333-php-4-to-php-5-upgrade-problems-wincludes/#findComment-557666 Share on other sites More sharing options...
gofer Posted October 22, 2008 Share Posted October 22, 2008 OK - call me a newbie... But don't think the original question had been answered? ??? 1. Why or what would make the php includes stop working with upgrade to PHP 5? I've made the same changes as mentioned here but get nothing parsed. Have good search engine ranking on .html pages; so changing pages to .php is not really an option. 2. Did the fact that allow_url_include is now Off have anything to do w/problem? I've already changed a couple of pages to use SSI include virtual statements but would rather stay w/PHP includes. 3. I can upload a copy of phpinfo() if that would help answer any questions. NOTE: I do not have access to server but am working w/hosting company person and do have direct way to contact them; so can get other info if it would help. Thanks and any help would be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/108333-php-4-to-php-5-upgrade-problems-wincludes/#findComment-672051 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.