TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Blank Page =( (http://www.talkphp.com/absolute-beginners/2436-blank-page.html)

obolus 03-08-2008 09:19 AM

Blank Page =(
 
I was making changes to my portfolio site on my computer (running Abyss w/ PHP v5.2.0 to test locally). I triple checked everything and fixed all the errors. So, I start uploading stuff to the web server my portfolio is hosted on (PHP v5.2.3). I open 'er up in my browser and I get a blank page (actually errors first, see below). Doh!

One of the changes I made, there is now a class method that includes an external file like so: include('xx/xx/filename.inc').

Originally the method looked something like this:

PHP Code:

<?php

function getPage($doc) {
  @(include(
"xx/xx/".$doc.".inc")) OR die('file not found');
}

?>

Pretty basic/simple. The die() is there as a quick and easy solution for a custom error message. It displays regardless of the @ at the beginning of the line. When I first uploaded to the web server I got the error message from the die() function. I checked everything out and all files and directories were right. Paths and permissions were fine as well. After that I changed the include line to this:

PHP Code:

<?php


function getPage($doc) {
  include(
"xx/xx/".$doc.".inc");
}

?>

...and that just got me a blank page. Now I'm stuck. Is there a difference in settings within each php.ini that might cause this? Difference in PHP versions? Did I totally miss something?

edit: To explain how the class works a little better...

The index.php file in the root folder grabs the requested page and passes it through a switch construct. It looks like this:


PHP Code:


switch ($_SERVER['QUERY_STRING'])

         case 
'blah':
     
$pgBuild = new Doc_Render();
     
$pgBuild->czHeader 'headblah';
     
$pgBuild->czContent 'blah';
     
$pgBuild->pgRender();
     break;

         default: 
     
$pgBuild = new Doc_Render();
     
$pgBuild->czHeader 'headerhome';
     
$pgBuild->czContent 'home';
     
$pgBuild->pgRender(); 


The Doc_Render class simply takes the 2 variables given, runs them through separate functions to find header and content files, and then displays the requested content.

Obviously including files isn't a problem since I was originally seeing the custom error messages coded within a class method. This is why I asked the questions above with regards to those include() lines inside of a class method.


thanks

SOCK 03-08-2008 09:39 AM

If when you say the file you're including is "external", meaning it's a URL, then yes. Check for the 'allow_url_fopen' and 'allow_url_include' settings on that host. See the PHP manual entry for using remote files.

If you have no control over the matter, you might look at using readfile() or the cURL extension.

I also recommend you get into the habit of using require_once() rather than include in almost every case. Why? Because the include_once() or require_once() functions ensure that each file is only included once, so no recursion, and the require_once() (or require()) adds the benefit of killing the script if the file isn't included.

Using the '@' error suppression symbol at the beginning of include() is a bit redundant - depending on your error_reporting setting, it will usually fail silently every time.

obolus 03-08-2008 05:52 PM

Nah, the included file is on the same server, just a different directory. I don't know why this is an issue only with the include() functions inside the class methods. There are include()'s in other pages (ie the ones that include the class file) and they seem to work fine.

I check the php.ini anyway for any differences:

allow_url_fopen: open on both
allow_url_include: off on both

Hrm. I looked through my code again this morning and still couldn't figure this out.

Thanks for the tip about switching to use require_once() or include_once(). =)

freenity 03-08-2008 06:08 PM

I guess there should be some problem with paths.
Check the folders you include the file from, on your server.
maybe try including with / at the beginning and writting a full path:
include_once('/folder/file.doc');

also remember is the server is unix based system it's case sensitive.

Salathe 03-08-2008 06:48 PM

Firstly when you're debugging, always set an appropriate error_reporting level (I like to report everything). A blank page with a bug is completely useless! I suspect it might be a simple path problem, but without knowing why the file isn't being included we can't offer particularly useful solutions.

Try using error_reporting(E_ALL | E_STRICT).

obolus 03-08-2008 07:40 PM

lol thanks freenity, that was the problem. Not sure why this server needs to have a different path then the one on my local test server.

I had to change dir/dir/file.inc to ./dir/dir/file.inc

Works fine now. Good call. =)

Salathe 03-08-2008 08:49 PM

That's a problem with the include_path value, there mustn't be an entry for ".".

obolus 03-09-2008 12:17 AM

Aye, that was it Sal.

I'll pay better attention to php.ini settings in the future when working off of 2 different servers.

Thanks all


All times are GMT. The time now is 02:53 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0