TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-08-2008, 09:19 AM   #1 (permalink)
The Acquainted
 
obolus's Avatar
 
Join Date: Oct 2007
Location: florida
Posts: 110
Thanks: 36
obolus is on a distinguished road
Default 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
obolus is offline  
Reply With Quote
Old 03-08-2008, 09:39 AM   #2 (permalink)
The Acquainted
 
Join Date: Nov 2007
Posts: 154
Thanks: 31
SOCK is on a distinguished road
Default

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.
__________________
I reject your reality, and substitute my own.
SOCK is offline  
Reply With Quote
The Following User Says Thank You to SOCK For This Useful Post:
obolus (03-08-2008)
Old 03-08-2008, 05:52 PM   #3 (permalink)
The Acquainted
 
obolus's Avatar
 
Join Date: Oct 2007
Location: florida
Posts: 110
Thanks: 36
obolus is on a distinguished road
Default

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(). =)
obolus is offline  
Reply With Quote
Old 03-08-2008, 06:08 PM   #4 (permalink)
The Acquainted
 
freenity's Avatar
 
Join Date: Feb 2008
Posts: 119
Thanks: 17
freenity is on a distinguished road
Default

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.
__________________
http://feudal-times.net - My PBB Game
http://gwphp.feudal-times.net - My Blog "Gaming With PHP"
freenity is offline  
Reply With Quote
The Following User Says Thank You to freenity For This Useful Post:
obolus (03-08-2008)
Old 03-08-2008, 06:48 PM   #5 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

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).
Salathe is offline  
Reply With Quote
Old 03-08-2008, 07:40 PM   #6 (permalink)
The Acquainted
 
obolus's Avatar
 
Join Date: Oct 2007
Location: florida
Posts: 110
Thanks: 36
obolus is on a distinguished road
Default

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. =)
obolus is offline  
Reply With Quote
Old 03-08-2008, 08:49 PM   #7 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

That's a problem with the include_path value, there mustn't be an entry for ".".
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
obolus (03-09-2008)
Old 03-09-2008, 12:17 AM   #8 (permalink)
The Acquainted
 
obolus's Avatar
 
Join Date: Oct 2007
Location: florida
Posts: 110
Thanks: 36
obolus is on a distinguished road
Default

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
obolus is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:19 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design