General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 22nd, 2002, 08:58 PM
wAr-AnGeL wAr-AnGeL is offline
Forum Security
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2002
Location: Behind You
Posts: 479 wAr-AnGeL User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m
Reputation Power: 7
Send a message via ICQ to wAr-AnGeL Send a message via AIM to wAr-AnGeL
Exclamation Include error

I'm trying to include a file in a function which is in a class.

include($DOCUMENT_ROOT . "/globals/somefilelalala.php");

This code works on all other pages except when I try to place it inside the function. I get the following error:

Warning: Failed opening '/globals/somefilelalala.php' for inclusion (include_path='.:/usr/local/lib/php') in /home/gotlag/public_html/template.php on line 8

Any ideas?

Note: I'm trying to make a template which needs some files included like menu, usersonline, etc...
__________________




"Only Linux users see the end of crashes."
- Pl4t0

Reply With Quote
  #2  
Old September 22nd, 2002, 09:10 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
War-Angel,

What version of PHP are you running? Try using $_SERVER['DOCUMENT_ROOT'].

Also, can you post the code where your code is contained.

Also, if that doesn't work, try this:

include("http://www.gotlag.com/<path-to-the-php-file>/file.php");

^^ Replace gotlag.com with whatever URL you're using it for.. I'm just assuming it's for your site.
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Last edited by FrankieShakes : September 22nd, 2002 at 09:17 PM.

Reply With Quote
  #3  
Old September 23rd, 2002, 12:17 AM
WittRaider WittRaider is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Posts: 1 WittRaider User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
or try this...

You always will need to "import" variables from the global scope into functions. So this will not work

PHP Code:
<?php
$foobar 
"abcd";

function 
fooMe() {
   echo 
$foobar;
}

?>


instead do this...

PHP Code:
<?php
$foobar 
"abcd";

function 
fooMe() {
   global 
$foobar;
   echo 
$foobar;
}

?>


Just remeber that modifying this value inside the function will actually modify the global value as well.

Another way to do it would be

PHP Code:
<?php
$foobar 
"abcd";

function 
fooMe() {
   echo 
$GLOBALS['foobar'];
}

?>


That would work in all PHP4 versions.

Reply With Quote
  #4  
Old September 23rd, 2002, 02:53 AM
Ben Rowe
Guest
Dev Articles Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
if you want to avoid the global, you can do this

foobar("testing");


then the function looks like

function foobar($test)
{
echo $test;
}

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Include error


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway