PHP Require Statements not working.

php require, server problem

Page 1 of 1

14 Replies - 8785 Views - Last Post: 04 November 2008 - 03:11 PM Rate Topic: -----

#1 gakattack  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 04-November 08

PHP Require Statements not working.

Post icon  Posted 04 November 2008 - 10:54 AM

So I have a script that starts off like this:
<?php
print 'test1';
require ('somefile.php');
print 'test2';

somefile.php starts off like this:
<?php
print 'test3'


When I run the main file, the output is 'test1'.... and the rest of the page is blank... Any ideas why? It worked before on the server, and my scripts also work on my localhost machine running the same version of php as the server...

I copied an old copy of the site onto the server, and it doesn't work either. It looks like a server problem. Anyone know the cause?

it's a linux server and the permissions on the files have been set

Is This A Good Question/Topic? 0
  • +

Replies To: PHP Require Statements not working.

#2 ghqwerty  Icon User is offline

  • if($spareTime > 0){ $this->writeCode(); }
  • member icon

Reputation: 43
  • View blog
  • Posts: 900
  • Joined: 08-August 08

Re: PHP Require Statements not working.

Posted 04 November 2008 - 10:59 AM

well i dont know if linux will make a differance but either make it

print ("test 1");
OR
echo "test 1"

also try using double quotes, ", for the require
Was This Post Helpful? 0
  • +
  • -

#3 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2890
  • View blog
  • Posts: 10,019
  • Joined: 08-August 08

Re: PHP Require Statements not working.

Posted 04 November 2008 - 11:08 AM

Is there a:
?>
ending somefile.php?
Was This Post Helpful? 0
  • +
  • -

#4 Moonbat  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 36
  • View blog
  • Posts: 424
  • Joined: 30-June 08

Re: PHP Require Statements not working.

Posted 04 November 2008 - 11:14 AM

According to what you posted, this line (print 'test3') in somefile.php doesn't have a semicolon at the end.

You should copy/paste your full code (no passwords or anything :P) instead of typing it manually here, so we can test it and see exactly what's wrong.
Was This Post Helpful? 0
  • +
  • -

#5 gakattack  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 04-November 08

Re: PHP Require Statements not working.

Posted 04 November 2008 - 11:16 AM

View PostCTphpnwb, on 4 Nov, 2008 - 10:08 AM, said:

Is there a:
?>
ending somefile.php?



There is a ?> at the end :/. The backup of the website that worked before I started working on it also worked before, now it doesn't.

I'm trying the double quotes at the moment.

View PostMoonbat, on 4 Nov, 2008 - 10:14 AM, said:

According to what you posted, this line (print 'test3') in somefile.php doesn't have a semicolon at the end.

You should copy/paste your full code (no passwords or anything :P) instead of typing it manually here, so we can test it and see exactly what's wrong.



i forgot a semi-colon in that example. the code has numerous include statements ..it'd be a big post
Was This Post Helpful? 0
  • +
  • -

#6 gakattack  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 04-November 08

Re: PHP Require Statements not working.

Posted 04 November 2008 - 12:28 PM

the double quote thing didn't work :/
Was This Post Helpful? 0
  • +
  • -

#7 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2890
  • View blog
  • Posts: 10,019
  • Joined: 08-August 08

Re: PHP Require Statements not working.

Posted 04 November 2008 - 12:44 PM

Keep it simple. Does this work? It works for me:

File1:
<?php
print 'test1';
require ('somefile.php');
print 'test2';
?>



somefile.php:
<?php
print 'test3';
?>


I just noticed that you're missing a ; at then end of print 'test3'

This post has been edited by CTphpnwb: 04 November 2008 - 12:46 PM

Was This Post Helpful? 0
  • +
  • -

#8 gakattack  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 04-November 08

Re: PHP Require Statements not working.

Posted 04 November 2008 - 12:53 PM

View PostCTphpnwb, on 4 Nov, 2008 - 11:44 AM, said:

Keep it simple. Does this work? It works for me:

File1:
<?php
print 'test1';
require ('somefile.php');
print 'test2';
?>



somefile.php:
<?php
print 'test3';
?>


I just noticed that you're missing a ; at then end of print 'test3'



that works, but the code on the webpages doesn't. it only does if i comment out all the require statements or make them include statements..I kinda need those in though. i could post the code, but it will be many many pages long :o
Was This Post Helpful? 0
  • +
  • -

#9 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2890
  • View blog
  • Posts: 10,019
  • Joined: 08-August 08

Re: PHP Require Statements not working.

Posted 04 November 2008 - 12:59 PM

Are you sure the filenames match? If include works but require doesn't, does include produce: "test1test3test2" or just "test1test2"? If it doesn't show test3, then I suspect a file name or path mismatch.
Was This Post Helpful? 0
  • +
  • -

#10 Hary  Icon User is offline

  • D.I.C Regular

Reputation: 44
  • View blog
  • Posts: 427
  • Joined: 23-September 08

Re: PHP Require Statements not working.

Posted 04 November 2008 - 01:02 PM

Probably a file error, but the php errors are suppressed. try increasing the php error level, or look in the log file what's wrong. this really sounds like a die() after an error...
Was This Post Helpful? 0
  • +
  • -

#11 gakattack  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 04-November 08

Re: PHP Require Statements not working.

Posted 04 November 2008 - 01:15 PM

View PostHary, on 4 Nov, 2008 - 12:02 PM, said:

Probably a file error, but the php errors are suppressed. try increasing the php error level, or look in the log file what's wrong. this really sounds like a die() after an error...



i'll try looking in the log. and my test program does produce "test1test3test2".

View Postgakattack, on 4 Nov, 2008 - 12:10 PM, said:

View PostHary, on 4 Nov, 2008 - 12:02 PM, said:

Probably a file error, but the php errors are suppressed. try increasing the php error level, or look in the log file what's wrong. this really sounds like a die() after an error...



i'll try looking in the log. and my test program does produce "test1test3test2".


error logging is disabled on the server....hm..
Was This Post Helpful? 0
  • +
  • -

#12 gakattack  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 04-November 08

Re: PHP Require Statements not working.

Posted 04 November 2008 - 01:31 PM

I found the error log!

So here's one error:
[Tue Nov 04 10:42:03 2008] [error] [client 192.168.5.129] PHP Fatal error: require() [<a href='function.require'>function.require</a>]: Failed opening required 'DIR_WS_INCLUDESheader.php'

the thing is, DIR_WS_INCLUDES is defined as....
define('DIR_WS_INCLUDES', 'includes/');
This path is correct, it just doesn't process as 'includes/'?

another error is:

[Tue Nov 04 10:43:00 2008] [error] [client 192.168.5.129] PHP Fatal error: Allowed memory size of 262144 bytes exhausted (tried to allocate 24576 bytes) in /export/home/opt/xampp/htdocs/oscom/includes/application_top.php on line 52



hm..
Was This Post Helpful? 0
  • +
  • -

#13 gakattack  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 04-November 08

Re: PHP Require Statements not working.

Posted 04 November 2008 - 02:02 PM

so now it's just the memory problem showing up in the error log..
Was This Post Helpful? 0
  • +
  • -

#14 Hary  Icon User is offline

  • D.I.C Regular

Reputation: 44
  • View blog
  • Posts: 427
  • Joined: 23-September 08

Re: PHP Require Statements not working.

Posted 04 November 2008 - 02:51 PM

Try to increase the mem limit in php.ini, 256k per php file is very little (or try to decrease the memory footprint (which is very hard to get under 256k for a large site)
Was This Post Helpful? 0
  • +
  • -

#15 gakattack  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 04-November 08

Re: PHP Require Statements not working.

Posted 04 November 2008 - 03:11 PM

View PostHary, on 4 Nov, 2008 - 01:51 PM, said:

Try to increase the mem limit in php.ini, 256k per php file is very little (or try to decrease the memory footprint (which is very hard to get under 256k for a large site)


Thanks Hary and everyone else, that should fix it. If not I'm sure I'll be continuing this thread ..
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1