Web Hosting Talk







View Full Version : php include_once problem


crashnet47
09-01-2004, 11:00 PM
I'm fairly new to php, so thank you in advance for bearing with me. Here is my problem:

I have a php file, ssi.php, that is located in public_html/wallpapers/ssi.php. I'm trying to use include_once to include that file in a file called skin_boards.php, located in public_html/forums/Skin/s3/skin_boards.php. I have tried EVERYTHING imaginable, absolute paths, literal paths, everything, but I keep getting these errors:

Warning: main(./wallpapers/ssi.php): failed to open stream: No such file or directory in /home/papered/public_html/forums/Skin/s3/skin_boards.php on line 20

Warning: main(): Failed opening './wallpapers/ssi.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/papered/public_html/forums/Skin/s3/skin_boards.php on line 20

I created a test page and put it in the public_html directory using the exact same code I'm using in skin_boards.php. It found ssi.php and worked perfectly. I moved the same file into forums/Skin/s3/ where skin_boards.php is located and it could not find ssi.php. Here's the directory structure and the file test.php:


Test file code:
<html>

<head>
<title>Test</title>
</head>

<body>
Testing
<?php
include_once("./wallpapers/ssi.php");
print cpg_thumb(1,1,5,"",0);
?>
</body>

</html>


public_html/
|____wallpapers/
|____ssi.php

public_html/
|____forums/
|____Skin/
|____s3/
|____skin_boards.php

First location of test file:
public_html/
***WORKED FINE HERE***

Second attempt with same file:
public_html/
|____forums/
|____Skin/
|____s3/
|____test2.php
***FAILED TO FIND SSI.PHP HERE***


With the fact that I tested the same file in both places and it worked in one and not the other help any? All files and folders are CHMODed properly to work. Again, thank you for bearing with me, I just REALLY want to get this to work. Thanks! :)

bhanson
09-01-2004, 11:23 PM
include_once("../../../wallpapers/ssi.php");

You have to trace it all the way back up.

../ - would get you back to "forums/Skin"
../../ - would get you back to "forums/"
../../../ - gets you back to your root directory so you can proceed back down to "wallpapers/ssi.php"

crashnet47
09-02-2004, 10:12 AM
Originally posted by bhanson
include_once("../../../wallpapers/ssi.php");

You have to trace it all the way back up.

../ - would get you back to "forums/Skin"
../../ - would get you back to "forums/"
../../../ - gets you back to your root directory so you can proceed back down to "wallpapers/ssi.php"

Well here's the kicker...I've actually tried that, several times. If you look at the code, I also used ./ to take me back to the root as well, but I still can't get it to find ssi.php. Does php have a limitation that would prevent me from being able to do this? :(

Thanks in advance for your help!

Burhan
09-02-2004, 10:18 AM
Check the permissions of the file.

barrywien
09-02-2004, 10:18 AM
Remove the dot and make the include path simple /wallpapers/ssi.php

armstrongecom
09-02-2004, 10:20 AM
I think you've got one little typo. Looks to me like...
include_once("./wallpapers/ssi.php");
Needs to be...
include_once("/wallpapers/ssi.php");

By having a leading dot in the path, you're making it start in the current directory, when what you really want is to start in the root directory. When your root directory test worked, it's because your current directory was already the root directory.

Hope this works... -Allen

pflangan
09-02-2004, 10:29 AM
your problem is down to the fact that you are using relative paths.

php will look for this file in the include path
php kind of tells you this. it said it couldn't find the file in the include path;
(include_path='.:/usr/lib/php:/usr/local/lib/php')


either link to the file as mentioned above using a series of relative ../../../../ etc. __OR__

DO as I do;

The way i include files relative to my www root directory is to use the $_SERVER['DOCUMENT_ROOT'] variable (do a search to find out more, it basically gives you the absolute path to the root folder of your website ;)

so for your site you would use:

include_once ($_SERVER['DOCUMENT_ROOT'] . "/wallpapers/ssi.php");

crashnet47
09-02-2004, 08:20 PM
Ok. I've tried doing this three times but I keep losing my post because I can't post URLs until I have 5 posts. Ok. I'm just going to be basic this time, and if you need more details, just ask. :)

I have two files, test2.php and skin_boards.php in the same directory - /forums/Skin/s3. Both test2.php and skin_boards.php have the same exact code inserted into it, as you will see below. skin_boards.php is combined with other php files to create a forum index page. test2.php works fine, but skin_boards.php with the same exact code still gives me the warnings posted above. Why would the same code work fine in one file, but not in the other? This is why I was having trouble in the first place with this, because I had tried ../../../ many times. Again, thank you in advance for any help you can provide! :)


test2.php
<html>

<head>
<title>Test</title>
</head>

<body>
Testing
<?php
include_once('../../../wallpapers/ssi.php');
print cpg_thumb(1,1,3,16,0);
?>
</body>

</html>



skin_boards.php

<?php

include_once('../../../wallpapers/ssi.php');


class skin_boards {

function whoschatting_show($total, $names, $link, $txt) {
global $ibforums;
return <<<EOF
<tr>
<th class='titlemedium' colspan='2'>{$total} {$ibforums->lang['whoschatting_total']} <a href='$link'>{$ibforums->lang['whoschatting_loadchat']}</a></th>
</tr>
<tr>
<td class='content' width='5%'><{S_ONLINE}></td>
<td class='content' width='95%'>{$names}<div class='desc' style='margin-top:5px'>$txt</td>
</tr>
EOF;
}

function whoschatting_empty($link) {
global $ibforums;
return <<<EOF
<tr>
<th class='titlemedium' colspan='2'>{$ibforums->lang['whoschatting_total']} <a href='$link'>{$ibforums->lang['whoschatting_loadchat']}</a></th>
</tr>
<tr>
<td class='content' width='5%'><{S_ONLINE}></td>
<td class='content' width='95%'><i>{$ibforums->lang['whoschatting_none']}</i></td>
</tr>
EOF;
}

function whoschatting_inline_link() {
global $ibforums;
return <<<EOF
{$ibforums->base_url}act=chat
EOF;
}

function whoschatting_popup_link() {
global $ibforums;
return <<<EOF
javascript:chat_pop({$ibforums->vars['chat_width']}, {$ibforums->vars['chat_height']});
EOF;
}

function active_list_sep() {
global $ibforums;
return <<<EOF
,
EOF;
}


function stats_header() {
global $ibforums;
return <<<EOF
<!--IBF.QUICK_LOG_IN-->
<br />
<div style='text-align: center;'>[ <a href='{$ibforums->base_url}act=Stats&amp;CODE=leaders'>{$ibforums->lang['sm_forum_leaders']}</a> |
<a href='{$ibforums->base_url}act=Search&amp;CODE=getactive'>{$ibforums->lang['sm_todays_posts']}</a> |
<a href='{$ibforums->base_url}act=Stats'>{$ibforums->lang['sm_today_posters']}</a> |
<a href='{$ibforums->base_url}act=Members&amp;max_results=10&amp;sort_key=posts&amp;sort_order=desc'>{$ibforums->lang['sm_all_posters']}</a> ]</div>
<br />
<!-- Board Stats -->
<div class='border'>
<div class='tableborder'>
<div style='float: right;padding:3px;'><{CAT_IMG}></div>
<div class='maintitle'><{CAT_IMG}>&nbsp;{$ibforums->lang['board_stats']}</div>
<table cellpadding='3' cellspacing='0' border='0' width='100%'>
EOF;
}

function ActiveUsers($active) {
global $ibforums;
return <<<EOF
<tr>
<th class='titlemedium' colspan='2'>$active[TOTAL] {$ibforums->lang['active_users']}</th>
</tr>
<tr>
<td class='content' width='5%'><{S_ONLINE}></td>
<td class='content' width='95%'><strong>{$active[GUESTS]}</strong> {$ibforums->lang['guests']}, <strong>$active[MEMBERS]</strong> {$ibforums->lang['public_members']} <strong>$active[ANON]
</strong> {$ibforums->lang['anon_members']} {$active['links']}<br /><br />{$active[NAMES]}</td>
</tr>
<!--IBF.WHOSCHATTING-->
EOF;
}

function active_user_links() {
global $ibforums;
return <<<EOF
[ {$ibforums->lang['oul_show_more']} <a href='{$ibforums->base_url}act=Online&amp;CODE=listall&amp;
sort_key=click'>{$ibforums->lang['oul_click']}</a>, <a href='{$ibforums->base_url}
act=Online&amp;CODE=listall&amp;sort_key=
name&amp;sort_order=asc&amp;show_mem=reg'>{$ibforums->lang['oul_name']}</a> ]
EOF;
}

function ShowStats($text) {
global $ibforums;
return <<<EOF
<tr>
<th class='titlemedium' colspan='2'>{$ibforums->lang['board_stats']}</th>
</tr>
<tr>
<td class='content' width='5%'><{S_STATS}></td>
<td class='content' width='95%'>$text<br />{$ibforums->lang['most_online']}</td>
</tr>
EOF;
}

function birthdays($birthusers="", $total="", $birth_lang="") {
global $ibforums;
return <<<EOF
<tr>
<th class='titlemedium' colspan='2'>{$ibforums->lang['birthday_header']}</th>
</tr>
<tr>
<td class='content' width='5%'><{S_BIRTHDAYS}></td>
<td class='content' width='95%'><strong>$total</strong> $birth_lang<br />$birthusers</td>
</tr>
EOF;
}



function calendar_events($events = "") {
global $ibforums;
return <<<EOF
<tr>
<th class='titlemedium' colspan='2'>{$ibforums->lang['calender_f_title']}</th>
</tr>
<tr>
<td class='content' width='5%'><{S_CALENDAR}></td>
<td class='content' width='95%'>$events</td>
</tr>
EOF;
}

function stats_footer() {
global $ibforums;
return <<<EOF
</table>
<{SPACER}>
</div>
</div>
<!-- Board Stats -->
EOF;
}

function bottom_links() {
global $ibforums;
return <<<EOF
<br />
<div style='float: right; text-align: right;'>[ <a href="{$ibforums->base_url}act=Login&amp;CODE=06">{$ibforums->lang['d_delete_cookies']}</a> ]<br /><br />[ <a href="{$ibforums-
>base_url}act=Login&amp;CODE=05">{$ibforums->lang['d_post_read']}</a> ]<br /><br />[ <{skin}> ]</div>
<div class='border' style='width: 400px;'>
<div class='tableborder'>
<div style='float: right;padding:3px;'><{CAT_IMG}></div>
<div class='maintitle'><{CAT_IMG}>&nbsp;<{TXT-FRM-LEGEND}></div>
<table width='100%' border='0' cellspacing='0' cellpadding='3' class='content'>
<tr>
<td><{C_ON}></td>
<td nowrap='nowrap'><{TXT-FRM-NEW}>&nbsp;</td>
<td><{C_OFF}></td>
<td nowrap='nowrap'><{TXT-FRM-NONEW}>&nbsp;</td>
</tr>
<tr>
<td><{C_ON_CAT}></td>
<td nowrap='nowrap'><{TXT-FRM-SUBNEW}>&nbsp;</td>
<td><{C_OFF_CAT}></td>
<td nowrap='nowrap'><{TXT-FRM-SUBNONEW}>&nbsp;</td>
</tr>
</table>
</div>
</div>
EOF;
}


function CatHeader_Expanded($Data) {
global $ibforums;
return <<<EOF
<div class='border'>
<div class='tableborder'>
<div style='float: right;padding:3px;'><{CAT_IMG}></div>
<div class='maintitle'><{CAT_IMG}>&nbsp;<a href="{$ibforums->base_url}c={$Data['id']}">{$Data['name']}</a></div>
<table width='100%' border='0' cellspacing='0' cellpadding='3'>
<tr>
<th width='2%' class='titlemedium'><img src='{$ibforums->vars['img_url']}/spacer.gif' alt='' width='28' height='1' /></th>
<th width='73%' class='titlemedium'>{$ibforums->lang['cat_name']}</th>
<th width='25%' class='titlemedium'>{$ibforums->lang['last_post_info']}</th>
</tr>
EOF;
}



function subheader() {
global $ibforums;
return <<<EOF
<br />
<div class='border'>
<div class='tableborder'>
<div style='float: right;padding:3px;'><{CAT_IMG}></div>
<div class='maintitle' align='left'><{CAT_IMG}></div>
<table width='100%' border='0' cellspacing='0' cellpadding='3'>
<tr>
<th class='titlemedium' width='2%'><img src='{$ibforums->vars['img_url']}/spacer.gif' alt='' width='28' height='1' /></th>
<th class='titlemedium' width='73%'>{$ibforums->lang['cat_name']}</th>
<th class='titlemedium' width='27%'>{$ibforums->lang['last_post_info']}</th>
</tr>
EOF;
}

function end_this_cat() {
global $ibforums;
return <<<EOF
</table>
<{SPACER}>
</div>
</div>
<br />
EOF;
}

function end_all_cats() {
global $ibforums;
return <<<EOF
<!--nothing-->
EOF;
}

function newslink( $fid="", $title="", $tid="" ) {
global $ibforums;
return <<<EOF
<strong>{$ibforums->vars['board_name']} {$ibforums->lang['newslink']} <a href='{$ibforums->base_url}showtopic=$tid'>$title</a></strong><br />
EOF;
}

function PageTop($lastvisit) {
global $ibforums;
return <<<EOF
<div align='left' style='text-align:left;padding:7px;'>
<!-- IBF.NEWSLINK -->
</div>
<!--<div class='border'>
<div class='tableboarder'>-->
<!--<table cellpadding="0" cellspacing="0" border="1" bordercolor="#000000" width="100%">
<tr><td>-->
<!--<div style="float: right;padding:3px;"><{CAT_IMG}></div>-->
<!-- WELCOMEPANEL -->
<!--</td>
</tr>
</table>-->
<!-- Borderline skin by InvisionSkins.com - copyright 2003 Goof Muilwijk [Roadkill71] -->
</div>
</div>
<br />
EOF;
}

function quick_log_in() {
global $ibforums;
return <<<EOF
<form style='display:inline' action="{$ibforums->base_url}act=Login&amp;CODE=01&amp;CookieDate=1" method="post">
<div style='text-align: right;'><strong>{$ibforums->lang['qli_title']}</strong>
<input type="text" class="forminput" size="10" name="UserName" onfocus="this.value=''" value="{$ibforums->lang['qli_name']}" />
<input type='password' class='forminput' size='10' name='PassWord' onfocus="this.value=''" value='ibfrules' />
<input type='submit' class='forminput' value='{$ibforums->lang['qli_go']}' />
</div>
</form>
<br />
EOF;
}

function forum_img_with_link($img, $id) {
global $ibforums;
return <<<EOF
<a href='{$ibforums->base_url}act=Login&amp;CODE=04&amp;f={$id}' title='{$ibforums->lang['bi_markread']}'>{$img}</a>
EOF;
}

function subforum_img_with_link($img, $id) {
global $ibforums;
return <<<EOF
<a href='{$ibforums->base_url}act=Login&amp;CODE=04&amp;f={$id}&amp;i=1' title='{$ibforums->lang['bi_markallread']}'>{$img}</a>
EOF;
}


function ForumRow($info) {
global $ibforums;
return <<<EOF
<tr>
<td class='content-b'>{$info['img_new_post']}</td>
<td class='content-b'><strong><a href='{$ibforums->base_url}showforum={$info['id']}'>{$info['name']}</a></strong><br />{$info['description']}<br />{$info
['moderator']}<br />[ {$ibforums->lang['topics']}: {$info['topics']} - {$ibforums->lang['replies']}: {$info['posts']} ]</td>
<td class="content-b" nowrap="nowrap">{$info['last_post']}<br />{$ibforums->lang['in']}:&nbsp;{$info['last_topic']} {$info['last_unread']}<br />{$ibforums->lang['by']}: {$info
['last_poster']}</td>
</tr>
EOF;
}

function forum_redirect_row($info) {
global $ibforums;
return <<<EOF
<!-- Forum {$info['id']} entry -->
<tr>
<td class='content-b'><{BR_REDIRECT}></td>
<td class='content-b'><strong><a href="{$ibforums->base_url}showforum={$info['id']}" {$info['redirect_target']}>
{$info['name']}</a></strong><br />{$info['description']}</td>
<td class='content-b'>{$ibforums->lang['rd_hits']}: {$info['redirect_hits']}</td>
</tr>
<!-- End of Forum {$info['id']} entry -->
EOF;
}

function forumrow_lastunread_link($fid, $tid) {
global $ibforums;
return <<<EOF
<a href='{$ibforums->base_url}showtopic=$tid&amp;view=getlastpost' title='{$ibforums->lang['tt_golast']}'><{LAST_POST}></a>
EOF;
}

function WelcomePanel($data="") {
global $ibforums;
return '
<div class="border">
<div class="tableborder">
<!--<div style="float: right;padding:3px;"><{CAT_IMG}></div>-->
<div class="maintitle"><{CAT_IMG}>&nbsp;Welcome Back, '.$ibforums->member['name'].'</div>
<table cellpadding="3" cellspacing="0" border="0" width="100%">
<tr>
<td class="content" align="center">'.$data['avatar'].'</td>
<td class="content" width="45%">It is now '.$data['time'].'<br />
Your last visit was on '.$data['lastv'].'<br />
Posts since your last visit: '.$data['posts_scince'].' '.$ibforums->lang['posts'].' in '.$data['topics_scince'].' topics<br /><br />
<a href="'.$ibforums->base_url.'act=Search&amp;CODE=getnew">'.$ibforums->lang
['new_posts'].'</a> | <a href="'.$ibforums->base_url.'act=Search&amp;CODE=getactive">'.$ibforums->lang['sm_todays_posts'].'</a>
</td>
<td class="content" width="55%">
Members: '.$data['stats']['MEM_COUNT'].' - '.$ibforums->lang['topics'].': '.$data['stats']['TOTAL_TOPICS'].' - Posts: '.$data['stats']['TOTAL_POSTS'].'<br />
Welcome to our newest member: <a href="'.$ibforums->base_url.'showuser='.$data['stats']['LAST_MEM_ID'].'">'.$data['stats']['LAST_MEM_NAME'].'</a><br />
'.$data['stats']['TOTAL'].' '.$ibforums->lang['active_users'].'<br />
'.$ibforums->lang['most_online'].'
</td>
</tr>
<tr>
<td class="content" colspan="3" width="100%">
print cpg_thumb(1,1,3,16,0);
</td>
</tr>
</table>
<!--</div>-->
<!--</div>-->';
}

function GuestPanel($data="") {
global $ibforums;
return '
<div class="border">
<div class="tableborder">
<!--<div style="float: right;padding:3px;"><{CAT_IMG}></div>-->
<div class="maintitle"><{CAT_IMG}>&nbsp;Welcome Guest! Please <a href="'.$ibforums->base_url.'&amp;act=Login&amp;CODE=00">login</a> or
<a href="'.$ibforums->base_url.'&amp;act=Reg&amp;CODE=00">register</a>! </div>
<table cellpadding="3" cellspacing="0" border="0" width="100%">
<tr>
<td class="content"><img src="style_images/<#IMG_DIR#>/noavatar.gif" border="0" alt="Guest avatar" /></td>
<td class="content" width="100%">It is now '.$data['time'].'<br />
There has been '.$data['posts_scince'].' '.$ibforums->lang['posts'].' in '.$data['topics_scince'].' topics today!<br />
<a href="'.$ibforums->base_url.'act=
Search&amp;CODE=getactive">'.$ibforums->lang['sm_todays_posts'].'</a><br />
'.$ibforums->lang['most_online'].'
</td>
<td class="content" align="right">
<form style="display:inline" action="'.$ibforums->base_url.'act=Login&amp;CODE=01&amp;CookieDate=1" method="post">
<table border="0" cellspacing="0" cellpadding="1">
<tr>
<td>Username:&nbsp;</td>
<td><input type="text" class="textinput" size="20" name="UserName" onfocus="this.value=\'\'" value="'.$ibforums->lang['qli_name'].'" /></td>
</tr>
<tr>
<td>Password:&nbsp;</td>
<td><input type="password" class="textinput" size="20" name="PassWord" onfocus="this.value=\'\'" value="ibfrules!" /></td>
</tr>
</table>
<div align="center"><input type="submit" class="forminput" value="Log me in" /></div>
</form>
</td>
</tr>
<tr>
<td class="content" colspan="3" width="100%">
print cpg_thumb(1,1,3,16,0);
</td>
</tr>
</table>
<!--</div>-->
<!--</div>-->';
}

}
?>