Page 1 of 1

Last Posts/Topics Code Not Working Quite Right

Posted: Tue Feb 23, 2010 10:16 am
by Pony99CA
I created my own versions of the code to show Last Posts and Last Topics based on the How to display posts and topics on external pages blog post. You can see my code on my board. It works well except for two problems:
  • The pages aren't styled correctly. There's no header or footer and the page title is wrong.
  • Viewing the pages logs me out of the board and I have to log back in.
I'm curious what I'm doing wrong as the main function seems to work perfectly.

Here are the links to the external pages:

Last 5 Topics
Last 5 Posts

Steve

Re: Last Posts/Topics Code Not Working Quite Right

Posted: Tue Feb 23, 2010 4:24 pm
by m157y
Try to remove script dir from cookies path at phpBB's configuration.
Just set it to / and nothing more.
Then try
P.S.
it'll kill all logged in statuses for your board, but it'll continue work after new login.
P.P.S.
I can't reproduce it on my localhost, but you have an little problem at
lastposts.php

Code: Select all

$bbcode = new bbcode(base64_encode($bbcode_bitfield));
$bbcode_bitfield wasn't defined before, for fixing just add before

Code: Select all

$bbcode_bitfield = $posts_row['bbcode_bitfield'];
Also your lasttopics.php contain a lot of not needed routines, i think you need to clean-up it :)

Edit: Ah, and i forgot. Please delete me from your board and provide a test account at next time.

Re: Last Posts/Topics Code Not Working Quite Right

Posted: Tue Feb 23, 2010 4:30 pm
by Brf
Yes. You need to change your cookie path to "/"
With it set to "/discuss/", the cookie is not valid in the parent folder.

Re: Last Posts/Topics Code Not Working Quite Right

Posted: Tue Feb 23, 2010 10:10 pm
by Pony99CA
Thanks for the reply.
m157y wrote:Try to remove script dir from cookies path at phpBB's configuration.
Just set it to / and nothing more.
Then try
P.S.
it'll kill all logged in statuses for your board, but it'll continue work after new login.
So that will basically make the cookie global to my whole site? That's fine with me. I only have one other real user right now, so logging him out won't be a big deal. :D
m157y wrote:P.P.S.
I can't reproduce it on my localhost, but you have an little problem at
lastposts.php

Code: Select all

$bbcode = new bbcode(base64_encode($bbcode_bitfield));
$bbcode_bitfield wasn't defined before, for fixing just add before

Code: Select all

$bbcode_bitfield = $posts_row['bbcode_bitfield'];
Also your lasttopics.php contain a lot of not needed routines, i think you need to clean-up it :)
You should probably let battye know about those. I pretty much took the lasttopics.php code from the blog post and lastposts.php from the site he linked to in the blog post. I think that I only changed the HTML templates and added another variable to lasttopics.php (and maybe fixed a bug and changed the SQL query a bit in one of them).

I'll look at mine, but I don't really use the code; I was just showing that other user on my board that it could be made to work. I was just curious why these things were happening.
m157y wrote:Edit: Ah, and i forgot. Please delete me from your board and provide a test account at next time.
I thought seeing the code would be sufficient; I didn't expect that you'd need to log in. Sorry for the bad assumption. Your account has been deleted.

Steve

Re: Last Posts/Topics Code Not Working Quite Right

Posted: Tue Feb 23, 2010 10:37 pm
by Pony99CA
Brf wrote:Yes. You need to change your cookie path to "/"
With it set to "/discuss/", the cookie is not valid in the parent folder.
As m157y and you agreed, I did as you suggested and changed the cookie path to "/". I also cleared all board cookies to get rid of the old ones.

Now when I log in, it says that I have successfully logged in, but when I get redirected to the Board Index, I'm logged out again. :? And, as I can't log in, I can't get into the ACP to try to fix things.

I'm using IE 7 (the only browser I have here) and even tried deleting all of my cookies from the Internet Options dialog. Still no luck....

Steve

Re: Last Posts/Topics Code Not Working Quite Right

Posted: Tue Feb 23, 2010 10:39 pm
by 3Di
use phpmyadmin or a similar tool to restore your cookie settings, in the meanwhile..

Re: Last Posts/Topics Code Not Working Quite Right

Posted: Tue Feb 23, 2010 10:53 pm
by Pony99CA
3Di wrote:use phpmyadmin or a similar tool to restore your cookie settings, in the meanwhile..
I just tried a different PC and was able to log in. And, even better, linking to those scripts no longer logs me out. :)

I assume the browser that I had open cached something (session, session cookies, whatever) which prevented me from logging on from that machine again (even after opening another browser window). I presume that closing all of my browser windows will fix the issue, but I can't do that right now.

So now that the second problem is probably fixed, what about the first one? Why aren't the page headers and footers displaying on those pages?

Thanks,
Steve

Re: Last Posts/Topics Code Not Working Quite Right

Posted: Tue Feb 23, 2010 11:00 pm
by 3Di
Pony99CA wrote:So now that the second problem is probably fixed, what about the first one? Why aren't the page headers and footers displaying on those pages?
in your html you need to 'include' both overall_header and overall_footer.htmls .. at the beginning and the bottom. I guess. On the fly. Have a look to the other .html files.

Re: Last Posts/Topics Code Not Working Quite Right

Posted: Tue Feb 23, 2010 11:24 pm
by m157y
Oh, sorry me, i missed second problem.
just add at your template files
at top

Code: Select all

<!-- INCLUDE overall_header.html -->
at bottom

Code: Select all

<!-- INCLUDE overall_footer.html -->

Re: Last Posts/Topics Code Not Working Quite Right

Posted: Wed Feb 24, 2010 6:00 am
by Pony99CA
m157y wrote:Oh, sorry me, i missed second problem.
just add at your template files
at top

Code: Select all

<!-- INCLUDE overall_header.html -->
at bottom

Code: Select all

<!-- INCLUDE overall_footer.html -->
Thanks to 3Di and you for that tip. I thought the calls to page_header and page_footer would include those files. I have to wonder why battye didn't mention those includes at all, either in his original blog post or his later blog post. :? I suppose if you want those items embedded in another page, you wouldn't want the page_header and page_footer calls.

Anyway, things are looking good now. The font's a little small, the block quotes in the last posts have text overlapping with the quotation marks and the list numbers in the last topics break the margin, but some CSS should clean that up.

Thanks again,
Steve

Re: Last Posts/Topics Code Not Working Quite Right

Posted: Wed Feb 24, 2010 12:22 pm
by Brf
Pony99CA wrote: I have to wonder why battye didn't mention those includes at all, either in his original blog post or his later blog post. :? I suppose if you want those items embedded in another page, you wouldn't want the page_header and page_footer calls.
That is correct. That article assumes you are embedding the topics into an external page with a different layout. The http://www.phpbb.com/kb/article/add-a-n ... -to-phpbb/ article shows you that you need the header and footer includes.

Re: Last Posts/Topics Code Not Working Quite Right

Posted: Fri Feb 26, 2010 12:21 am
by Pony99CA
Pony99CA wrote:I assume the browser that I had open cached something (session, session cookies, whatever) which prevented me from logging on from that machine again (even after opening another browser window). I presume that closing all of my browser windows will fix the issue, but I can't do that right now.
That turned out not to be the case. On my home PC, I used phpBB's Delete all board cookies function and even rebooted my PC and I still couldn't log in to my board in Firefox 3.6. I actually had to manually delete the phpBB cookies using Firefox's Tools before I could log in again.

Is that a bug in the Delete all board cookies function? If a board admin changes his cookie setting, this seems to badly break the login process even if the user used the Delete all board cookies function. How are normal users supposed to figure this out?

Steve

Re: Last Posts/Topics Code Not Working Quite Right

Posted: Fri Feb 26, 2010 12:41 am
by Pony99CA
Brf wrote:
Pony99CA wrote: I have to wonder why battye didn't mention those includes at all, either in his original blog post or his later blog post. :? I suppose if you want those items embedded in another page, you wouldn't want the page_header and page_footer calls.
That is correct. That article assumes you are embedding the topics into an external page with a different layout. The http://www.phpbb.com/kb/article/add-a-n ... -to-phpbb/ article shows you that you need the header and footer includes.
It certainly does. I just didn't expect that given the calls to page_header and page_footer. It seems odd that they don't generate those (I haven't tried to follow that process, so it may not be technically possible or desirable), but at least I know the rules now. :)

Of course, I still wonder why he'd show calling page_header and page_footer without at least mentioning adding the includes of overall_header.html and overall_footer.html. Would calling those functions be useful in any other context where you weren't including the templates?

Thanks,
Steve

Re: Last Posts/Topics Code Not Working Quite Right

Posted: Fri Feb 26, 2010 12:14 pm
by Brf
The page_header does the initial "header:" and fills in a bunch of template variables.
The page_footer generates the debug variables, initiates the template 'body' call and cron, and call-exits the script.

I suppose neither is required if you do not need any of the variables, as long as you

Code: Select all

$template->display('body');
manually.

Re: Last Posts/Topics Code Not Working Quite Right

Posted: Fri Feb 26, 2010 1:09 pm
by m157y
but if you plan don't use page_footer(); i think it'll be good if you'll call garbage_collection();. Because it's unloading cache(which was loaded on session init) and also it'll close connection to db, which was initiated at common.php.