Current time: 04-23-2014, 08:52 PM Hello There, Guest! (LoginRegister)

Post Reply 
PHP: include()
04-20-2011, 05:23 AM
Post: #1
PHP: include()
I'm migrating from GoDaddy and for some reason my website no longer works. It uses php include() pretty heavily to make life simpler. I tried adding a .htaccess with this added:

AddHandler application/x-httpd-php .html .htm .php

I also tried switching the PHP Mode in the Web Panel from 5.2 FastCGI to 5.3 CGI.

In my example below all that seems to show up no matter what page I try to load is the index.php with default.html showing.

I'm sure its a problem with the server as my code worked fine on another host.

In my index.php I try to include a page by using the url ("index.php?s=page1") and this is the php code in index.php
PHP Code:
<?php
$doc_root 
$_SERVER['DOCUMENT_ROOT'];
switch (
$s
{             
    case 
"page1":
               include (
"$doc_root/page1.php");
               break;    
                     
    case 
"page2":
              include (
"$doc_root/page2.php");
              break;

        default:
              include(
"$doc_root/default.html");
              break;
}
?>

I also have inside each of the pageX.php files the ability to include html so that I can have urls like ("index.php?s=page1&p=subpage1").

PHP Code:
<?php
$doc_root 
$_SERVER['DOCUMENT_ROOT'];
switch (
$p
{             
    case 
"subpage1":
               include (
"$doc_root/subpage1.html");
               break;    
                     
    case 
"subpage2":
              include (
"$doc_root/subpage2.html");
              break;
}
?>
Find all posts by this user
Quote this message in a reply
04-20-2011, 11:02 AM
Post: #2
RE: PHP: include()
In index.php, you're depending on PHP's deprecated register_globals feature, which is not enabled on our servers. Adding the following line to index.php will solve the problem:

Code:
$s = $_GET["s"];

You'll need something analogous for $p as well.
Find all posts by this user
Quote this message in a reply
04-20-2011, 08:07 PM
Post: #3
RE: PHP: include()
Ah thanks that worked perfectly.

Is it still advised to use the full paths using:

$doc_root = $_SERVER['DOCUMENT_ROOT']; ?

Also what PHP Mode should I be using? Theres at least four options and I'm not really sure what the difference is between them.


Thanks
Find all posts by this user
Quote this message in a reply
04-20-2011, 08:21 PM
Post: #4
RE: PHP: include()
Quote:Is it still advised to use the full paths using:

$doc_root = $_SERVER['DOCUMENT_ROOT']; ?
Not necessary, and not recommended. The working directory (i.e, the directory from which paths will be calculated) defaults to the directory containing your PHP script.

Quote:Also what PHP Mode should I be using? Theres at least four options and I'm not really sure what the difference is between them.
For new applications, I'd recommend PHP 5.3 FastCGI. Here's the scoop:
  • 5.2 vs. 5.3: Different versions of the PHP interpreter. 5.2 is nearing end-of-life, but not all PHP extensions (or applications!) are fully compatible with 5.3 yet, so we've got to support both for a while longer. 5.3 is considerably faster, and supports some easier ways to customize it, so there's really no reason not to use it for a new application.
  • CGI vs. FastCGI vs. mod_php (the latter only on VPS and dedicated servers): Different ways of running the PHP script. FastCGI works great for most applications, but a few will work better as CGI for various reasons, and mod_php will provide some performance benefits on VPS/dedicated for certain applications.
Find all posts by this user
Quote this message in a reply
04-20-2011, 08:36 PM
Post: #5
RE: PHP: include()
Thanks a lot for the quick responses they have been really helpful Smile
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump: