View Full Version : Issue with vBulletin php include on non vb page
DandD
10-06-2008, 12:14 AM
We have a new site on which we use a php include to display calendar.php on the home page. It seems to work well with two exceptions. Fist, we noticed the calendar view links are not in the proper place and second, the user login status is incorrect (user is not shown as logged in when he is). These problems are on the home page (root folder - index.php), but the calendar.php page in the forum folder works correctly.
The site home page is: www.lahabraevents.com
The calendar page is: www.lahabraevents.com/forum/calendar.php
We suspect the problem is a sessions issue due to the home page being in the root folder rather than the forum folder, but we need help from someone a little more knowledgable. Any help is appreciated.
Lynne
10-06-2008, 03:21 AM
Did you make sure to include the global.php in the page?
Marco van Herwaarden
10-06-2008, 07:44 AM
Chdir() to the forum directory before including the calendar.php.
DandD
10-07-2008, 03:37 AM
Thanks for the replies.
Lynne, yes we included global.php both on the page and it is also in the calendar.php include but no joy.
Marco, we tried using Chdir but we aren't familiar enough to know how to use it properly. If you could give us some guidance, that would be great. When we tried, we got the dreaded "Unable to add cookies, header already sent." message.
Thanks in advance for any help.
Marco van Herwaarden
10-07-2008, 10:07 AM
chdir('/path/to/your/forum/');
DandD
10-07-2008, 03:32 PM
chdir('/path/to/your/forum/');
Hi Marco,
Thanks for the reply. Unfortunately, that is the code I have tried before in numerous variations along with other coded edits - full paths, relative paths, etc. - with no success. Either I still have the original problems at best, or worse, some sort of error code. Any further help is certainly appreciated. Here is the current code for the page (if I don't include the base href, I lose the CSS). BTW, this is a test page in the same directory as index.php. The url is http://www.lahabrevents.com/index-test.php.:
<base href="http://www.lahabraevents.com/forum/" />
<?php chdir('/forum/'); include ("http://www.lahabraevents.com/forum/calendar.php"); ?>
thanks,
David
Dismounted
10-08-2008, 05:50 AM
Why do you include the whole calendar.php page - this will most likely create errors. either replicate calendar.php's code, or modify it to meet your needs.
DandD
10-08-2008, 12:20 PM
Why do you include the whole calendar.php page - this will most likely create errors. either replicate calendar.php's code, or modify it to meet your needs.
Hi Dismounted,
Thanks for the thoughts. Admittedly I am a novice, so please bear with me. It seems the problem is due to relative paths in all the files. The site home page (the page in question) is in the root folder. The calendar.php file is in the /forum/ folder. If I understand your suggestion correctly, I can copy the calendar.php code into the home page rather than using an include. I tried this and modified the paths on all the includes for that file accordingly. But we then have the same problem with the first file called down the line - in this case my modified code can now find /forum/global.php but returns an error because /includes/init.php can't be found. I would then need to modify the path in global.php and so on back to who knows where. That seems more than a little convoluted, not to mention opening the door to other issues.
Hopefully I am missing something simple. As you can tell I could really use some guidance.
Thanks for any help.
David
:eek:
noppid
10-08-2008, 01:29 PM
preface urls in your templates as...
$vboptions[bburl]
Maybe?
DandD
10-08-2008, 04:55 PM
preface urls in your templates as...
$vboptions[bburl]
Maybe?
Hi noppid,
Thanks for that. Tried it with same result. It appears I would need to modify all the include files and still not sure if that would work.
David
noppid
10-08-2008, 05:00 PM
Then you need something like in vBa CMPS that does a search and replace I guess.
Dismounted
10-09-2008, 02:49 AM
Hi Dismounted,
Thanks for the thoughts. Admittedly I am a novice, so please bear with me. It seems the problem is due to relative paths in all the files. The site home page (the page in question) is in the root folder. The calendar.php file is in the /forum/ folder. If I understand your suggestion correctly, I can copy the calendar.php code into the home page rather than using an include. I tried this and modified the paths on all the includes for that file accordingly. But we then have the same problem with the first file called down the line - in this case my modified code can now find /forum/global.php but returns an error because /includes/init.php can't be found. I would then need to modify the path in global.php and so on back to who knows where. That seems more than a little convoluted, not to mention opening the door to other issues.
Hopefully I am missing something simple. As you can tell I could really use some guidance.
Thanks for any help.
David
:eek:
As Marco has said - you can use chdir(). This will change the working directory to whatever you want.
DandD
10-09-2008, 06:42 AM
As Marco has said - you can use chdir(). This will change the working directory to whatever you want.
Hi Dismounted,
I really appreciate your help. This has been quite strange. I was repeatedly getting error codes when trying to use the chdir but now I'm not and everything seems to be working with the exact same code I tried before. I mean exactly. There is one other problem now: I have additional html on the page after the php tags which simply does not show up now, not on the page, not on the page source code. Is there a trick I'm missing?
Edit: I spoke too soon. Before I would get the errors in Firefox immediately and eventually in Safari. Tonight all seemed well in Safari, even after clearing the cache. In Firefox, I again get the error message:
Unable to add cookies, header already sent.
File: /home/xxxx/public_html/index-test.php
Line: 2
Here is the entire code I'm trying now:
<base href="forum/" />
<?php chdir('forum/'); ?>
<?php include ("calendar.php"); ?>
(If I don't use the base href the css does not work. I even tried a link href for the .css file instead but it does not work.)
This is the page: http://www.lahabraevents.com/index-test.php
I feel like I am going crazy. Obviously, I could use any help you could offer. Much thanks.
David
Dismounted
10-09-2008, 07:04 AM
Add your base element in the headinclude template, and use an absolute URL (http://www.site.com/forum). Use absolute paths (i.e. /home/user/public_html) for chdir().
DandD
10-09-2008, 08:51 AM
Add your base element in the headinclude template, and use an absolute URL (http://www.site.com/forum). Use absolute paths (i.e. /home/user/public_html) for chdir().
Dismounted,
I feel like I should apologize for taking your time. You have been most gracious. I would like to think we are making progress. I added the base element to the headinclude template using the absolute URL as suggested. I added to the index-test.php page:
chdir('/home/xxxx/public_html/forum')
The CSS worked in Safari but not Firefox on the index page. I added a link href to the .css file in the index page and now that works (I had to use the absolute URL, relative did not work).
I no longer get error messages and my html footer now displays again. Unfortunately, the original issue remains. The user login status and the calendar view links do not display correctly. I am wondering if this is related to the include itself. If I use a relative path, the page does not work, I only get error codes. The code now is:
include ("http://www.lahabraevents.com/forum/calendar.php");
If you have a magic wand to make this work, I would be most appreciative.
Thanks again,
David
Dismounted
10-09-2008, 09:15 AM
And the errors are?...
DandD
10-09-2008, 04:58 PM
And the errors are?...
With this current code, no errors but still the original issues:
headinclude
base href="http://www.lahabraevents.com/forum/"
index-test.php
chdir('/home/xxxx/public_html/forum')
link href="http://www.lahabraevents.com/forum/clientscript/vbulletin_css/style-b391d83b-00002.css" rel="stylesheet" type="text/css"
include ("http://www.lahabraevents.com/forum/calendar.php");
Error
If I change the include to a relative path, I get the same errors I have been fighting.
include ("calendar.php");
Error:
Unable to add cookies, header already sent.
File: /home/xxxx/public_html/index-test.php
Line: 7
Hopefully I am missing something simple.
Thanks again,
David
Lynne
10-09-2008, 05:18 PM
It is very hard to tell what you have done since you are not using the php or html tags to quote exactly what you code is. One thing I have noticed it your chdir is not ending in a slash and then your include is not starting with a slash. Perhaps that is a problem? I would try:
chdir('/home/xxxx/public_html/forum');
include ("./calendar.php");
DandD
10-09-2008, 06:12 PM
It is very hard to tell what you have done since you are not using the php or html tags to quote exactly what you code is. One thing I have noticed it your chdir is not ending in a slash and then your include is not starting with a slash. Perhaps that is a problem? I would try:
chdir('/home/xxxx/public_html/forum');
include ("./calendar.php");
Hi Lynne,
Thanks for the suggestion. I have tried so many variations I have ended up going in circles. The above gives the same error code. If I add a slash to the end of the chdir path and use any relative path variation for the include, same error. If I add a slash to the chdir path and use the absolute path for the include, no error but the original issue exists. Examples:
1
chdir('/home/xxxx/public_html/forum');
include ("calendar.php");
Error
Unable to add cookies, header already sent.
File: /home/xxxx/public_html/index-test.php
Line: 7
2
chdir('/home/xxxx/public_html/forum');
include ("/calendar.php");
Error
Warning: main(/calendar.php) [function.main]: failed to open stream: No such file or directory in /home/xxxx/public_html/index-test.php on line 8
Warning: main(/calendar.php) [function.main]: failed to open stream: No such file or directory in /home/xxxx/public_html/index-test.php on line 8
Warning: main() [function.include]: Failed opening '/calendar.php' for inclusion (include_path='.:/usr/lib/php') in /home/xxxx/public_html/index-test.php on line 8
3
chdir('/home/xxxx/public_html/forum');
include ("./calendar.php");
Error
Unable to add cookies, header already sent.
File: /home/xxxx/public_html/index-test.php
Line: 7
4
chdir('/home/xxxx/public_html/forum');
include ("/home/xxxx/public_html/forum/calendar.php");
Error
Unable to add cookies, header already sent.
File: /home/xxxx/public_html/index-test.php
Line: 7
5
chdir('/home/xxxx/public_html/forum');
include ("http://www.lahabraevents.com/forum/calendar.php");
Page displays, no errors, but original issues unresolved.
thanks,
David
Lynne
10-09-2008, 08:59 PM
But, what is your entire code? Unable to add cookies usually means you have it doing 'header-type' stuff twice. Once you start to write your page, you can't go back and try to set a cookie again. So, it could be that you are doing things out-of-order in your page. You may have to try rearranging your php.
Dismounted
10-10-2008, 05:09 AM
"Unable to add cookies" means you have sent output to the browser before the script could send cookie headers. Whitespace is considered output.
Marco van Herwaarden
10-10-2008, 08:56 AM
Please also post the contents of index-test.php.
DandD
10-10-2008, 11:44 PM
Hey guys,
Thanks to all of you for your continued support. I've stripped down the code to the bare minimum. Currently this is the entire code for the index-test.php page:
=========
<?php chdir('/home/xxxx/public_html/forum'); ?>
<link href="http://www.lahabraevents.com/forum/clientscript/vbulletin_css/style-b391d83b-00002.css" rel="stylesheet" type="text/css">
<?php include ("http://www.lahabraevents.com/forum/calendar.php"); ?>
=========
As previously suggested I added to the headinclude template:
=========
base href="http://www.lahabraevents.com/forum/"
=========
I've tried various combinations of code, changing the order, making sure to delete white space, etc. but still can't get this to work. (I have also tried putting the two php code elements within the same php tags with no difference. The reason they are separate is I need to use some table tags for layout.) As the code is above, the calendar loads on the page and there are no error codes but the login status and calendar view links are not correct. If I make the include path relative ("calendar.php"), we get the error:
"Unable to add cookies, header already sent.
File: /home/xxxx/public_html/index-test.php
Line: 3"
I understand the idea there may be conflict due to duplicate header calls. I just don't know how to avoid it. As Dismounted previously suggested, I've tried using the calendar.php code on the index page rather than using an include but I don't know how to delete the header call - IF that is what I need to do.
Once again, I appreciate any other ideas or suggestons.
David
Dismounted
10-11-2008, 04:12 AM
In your code:
<?php chdir('/home/xxxx/public_html/forum'); ?>
<link href="http://www.lahabraevents.com/forum/clientscript/vbulletin_css/style-b391d83b-00002.css" rel="stylesheet" type="text/css">
<?php include ("http://www.lahabraevents.com/forum/calendar.php"); ?>
Your second line is output. global.php (which is included in calendar.php), will most likely set cookies. That can't happen because you've already sent output to the browser.
DandD
10-11-2008, 06:10 AM
In your code:
<?php chdir('/home/xxxx/public_html/forum'); ?>
<link href="http://www.lahabraevents.com/forum/clientscript/vbulletin_css/style-b391d83b-00002.css" rel="stylesheet" type="text/css">
<?php include ("http://www.lahabraevents.com/forum/calendar.php"); ?>
Your second line is output. global.php (which is included in calendar.php), will most likely set cookies. That can't happen because you've already sent output to the browser.
By the second line, I assume you mean the link href code. After more testing I can get things to work but it appears I cannot have ANY html between the two above lines of php, not even some table tags where I wanted to place the include file. And any html on the page after the php is ignored - my added footer does not display. Not the end of the world - at least we have fixed the main issue.
Thanks again everyone for all the help. I really do appreciate it.
David
Dismounted
10-11-2008, 10:41 AM
By the second line, I assume you mean the link href code. After more testing I can get things to work but it appears I cannot have ANY html between the two above lines of php, not even some table tags where I wanted to place the include file.
That is correct. Any character sent to the browser is considered output. HTML is sent directly to the browser.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.