Sessions!!!!!

Discussion forum for MOD Writers regarding MOD Development.
User avatar
LiquidSpark
Registered User
Posts: 146
Joined: Thu Mar 29, 2007 6:54 pm

Sessions!!!!!

Post by LiquidSpark »

Alright, folks, I've spent a month trying to figure this out. I've read at least 15 discussions on 3 different forums and I still cannot get this to work:

1. Please explain how to pass user sessions via forum links. A forum link is the type of forum new to Olympus that is simply a link, rather than a category or forum.

2. Please explain EXACTLY WHAT IS NEEDED in order to pass a user session to a new ".php" page in the forum root folder. I've tried all that stuff like...

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

page_header('your_page_name');

$template->set_filenames(array(
    'body' => 'your_html_file.html',
));

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
page_footer();
?>
along with the corresponding HTML file

Code: Select all

<!-- INCLUDE overall_header.html -->

<h2>Your_Page_Name</h2>

<div class="panel">
   <div class="inner"><span class="corners-top"><span></span></span>

   <div class="content">
      <p>
         Content in here.
      </p>
   </div>

   <span class="corners-bottom"><span></span></span></div>
</div>

<!-- INCLUDE jumpbox.html -->
<!-- INCLUDE overall_footer.html -->
and putting this stuff in the linked php file:

Code: Select all

if($user->data['is_registered'])
{
stuff
}
...but nothing seems to work. I don't need to change my cookie path, I don't need to do any of that other ****, just tell me exactly what to do please. This is pissing me off.
dvt85
Registered User
Posts: 130
Joined: Tue Sep 11, 2007 1:57 am

Re: Sessions!!!!!

Post by dvt85 »

bumify
User avatar
LiquidSpark
Registered User
Posts: 146
Joined: Thu Mar 29, 2007 6:54 pm

Re: Sessions!!!!!

Post by LiquidSpark »

*Bump* (I know it's soon, but somebody has to know an answer to my first question... come on, who made this phpBB thing anyway?)

As a side note, this code works to display the content in the style's template:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

page_header('SF Teacher Search');

$template->set_filenames(array(
    'body' => 'teachersearch.html',
));

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
page_footer();
?>
I used the above code to display "teachersearch.html" in the style of my forum. That html file is now displayed like it's another page of the forum. It has a form the user fills out and submits to a .php file. However, that .php file does not appear in the style of the forum. I want it to. How do I do this without using the same code I used for the .html file (it won't work this way).
User avatar
A_Jelly_Doughnut
Former Team Member
Posts: 34459
Joined: Sat Jan 18, 2003 1:26 am
Location: Where the Rivers Run

Re: Sessions!!!!!

Post by A_Jelly_Doughnut »

1) There is no good way to attach a session ID to a link forum. I suppose some kind of regular expression match could be used to make sure the link points to your site, then run append_sid.

2) Your page integration looks fine. Make sure you use append_sid() for links between pages of your site to continue the session across all pages. 1 could be the cause of 2, since append_sid is not used there.

3) What is the code you are using after the form is submitted? trigger_error() is usually enough for a success/failure page, and it should be styled properly.
A Donut's Blog
"Bach's Prelude (Cello Suite No. 1) is driving Indiana country roads in Autumn" - Ann Kish
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53629
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Sessions!!!!!

Post by Brf »

LiquidSpark wrote: However, that .php file does not appear in the style of the forum.
Does it have:

Code: Select all

<!-- INCLUDE overall_header.html -->
at the top? The overall_header is what makes all of your forum pages look alike.
User avatar
LiquidSpark
Registered User
Posts: 146
Joined: Thu Mar 29, 2007 6:54 pm

Re: Sessions!!!!!

Post by LiquidSpark »

A_Jelly_Doughnut wrote:1) There is no good way to attach a session ID to a link forum. I suppose some kind of regular expression match could be used to make sure the link points to your site, then run append_sid.

2) Your page integration looks fine. Make sure you use append_sid() for links between pages of your site to continue the session across all pages. 1 could be the cause of 2, since append_sid is not used there.

3) What is the code you are using after the form is submitted? trigger_error() is usually enough for a success/failure page, and it should be styled properly.
1) What is a 'regular expression match'?

2) Cookies aren't doing anything to help me, either. I have cookies enabled and they're set to the right location for my forum, but the session just will not remain unless the SID is appended. So much for cookies! I'll eat cake, instead. :x

3) I remember seeing "trigger_error()" mentioned somewhere around here, but since I didn't make phpBB 3.0 and since I don't have the time to analyze how it was made, I have no idea what functions it uses or how they work. Please explicate your suggestion. Sounds like it somehow works with sessions... :?
Brf wrote:
LiquidSpark wrote: However, that .php file does not appear in the style of the forum.
Does it have:

Code: Select all

<!-- INCLUDE overall_header.html -->
at the top? The overall_header is what makes all of your forum pages look alike.
<!-- INCLUDE overall_header.html --> didn't do anything in the php form-info-post file. Does it matter that the .php file is inside another folder within the phpBB3 root directory; does it have to be phpBB3/file.php, or can it be phpBB3/potatoes/file.php?
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53629
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Sessions!!!!!

Post by Brf »

That overall_header would have to be included in your
'your_html_file.html'
User avatar
LiquidSpark
Registered User
Posts: 146
Joined: Thu Mar 29, 2007 6:54 pm

Re: Sessions!!!!!

Post by LiquidSpark »

I'm not using an HTML file!
I'm using a PHP file!

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

page_header('SF Teacher Search');

$template->set_filenames(array(
    'body' => 'teachersearch.html',
));

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
page_footer();
?>
There is an HTML page that uses the above code and is working well. This HTML page has form. The user fills out the form and presses the "submit" button. The form data is sent to a PHP file. I want that PHP file to be in the same style as the forum. How do I do this.

I think I will need an alternative to the above code, because I need to use "echo" and some php variables.
...On fifth thought, maybe I'll try embedding the php variables into 'teachersearch.html'. Nevertheless, there must be a cleaner alternative to the method displayed in the above code.

EDIT: That won't work, what was I thinking, IT'S A FORM.
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53629
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Sessions!!!!!

Post by Brf »

LiquidSpark wrote: 'body' => 'teachersearch.html',
Your teachersearch.html needs the overall_header include.
That is what makes the page look like your forum.
User avatar
LiquidSpark
Registered User
Posts: 146
Joined: Thu Mar 29, 2007 6:54 pm

Re: Sessions!!!!!

Post by LiquidSpark »

Thanks for your quick response, but like I've said many times now, 'teachersearch.html' is working just fine. It's displayed properly, and uses the method outlined in the code above. Ignore this file now, I'm not dealing with it.

The file in question is the search.php file where the form data is sent. In 'teachersearch.html', I press a submit button and the form data is sent to search.php. So I need to put something in search.php in order for it to be displayed in the phpBB forum style.

I tried embedding the search.php data between <?php> tags in a search.html file to be displayed like the teachersearch.html was displayed. That only showed the Page Header -- none of the form data went through to the embedded html page.

I looked at how the register.php file works (it also uses form data), but all I saw were a bunch of internal phpBB functions. Apparently, Olympus is a pain in the *** to modify: I can't pass sessions through forum links, and I can't even create new pages without using the embedded HTML template.

I tried applying the "overall_header" stuff to a php file. That didn't work, in any way I did it. So apparently it has to be in an HTML file, and according to the docs, i can't put <html> before it to use it in a php file: "don't put anything before this!", so I can't embed it in the php file.

I'm so annoyed right now that I want to cut-and-paste the raw header data into the file!!!!
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53629
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Sessions!!!!!

Post by Brf »

phpBB php files use an html template as described above. The include of the overall_header.html in that html template is what makes the page "look like" your forum.
User avatar
LiquidSpark
Registered User
Posts: 146
Joined: Thu Mar 29, 2007 6:54 pm

Re: Sessions!!!!!

Post by LiquidSpark »

I understand this.

But when I send a form to a .php file, how do I get that .php file to look like the phpBB forum?

Consider:

"Alpha.php" is this:

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

page_header('Beta');

$template->set_filenames(array('body' => 'beta.html',));

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
page_footer();
?>
"Alpha.php" is using the template to display "Beta.html" in the forum's style.

"Beta.html" is this:

Code: Select all

<!-- INCLUDE overall_header.html -->
<h2>My Beta Page :D</h2>
<div class="panel">
	<div class="inner">
		<span class="corners-top">
			<span></span>
		</span>
		<div class="content">
			<!--Begin Form-->
			<form action="gamma.php" method="post">
				<table border="0" width="50%">
					<tr>
						<td>
							What is your name?
						</td>
						<td>
							<input type="text" name="my_name" size="25" maxlength="25" />
						</td>
					</tr>
				</table>
				<input type="submit" value="Submit my Name!"/>
			</form>
			<!--End Form-->
		</div>
		<span class="corners-bottom">
			<span></span>
		</span>
	</div>
</div>
<!-- INCLUDE jumpbox.html -->
<!-- INCLUDE overall_footer.html -->
As you can see in "Beta.html", I want the form data passed to "Gamma.php". But I need "Gamma.php" to be displayed like it's a part of the forum.

Example 1 does not work as "Gamma.php":

Code: Select all

<!-- INCLUDE overall_header.html -->
<h2>Gamma!</h2>
<div class="panel">
	<div class="inner">
		<span class="corners-top">
			<span></span>
		</span>
		<div class="content">
		<?php
		LALALALLALALA some embedded php content LALALALALALLA
		?>
		</div>
		<span class="corners-bottom">
			<span></span>
		</span>
	</div>
</div>
<!-- INCLUDE jumpbox.html -->
<!-- INCLUDE overall_footer.html -->
... because the embedded php content does not display.

In using "Gamma.php" or "Gamma.html", Example 2 will not work:
(The following page is "Delta.php")

Code: Select all

<?php
define('IN_PHPBB', true);
$phpbb_root_path = './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup();

page_header('Gamma');

$template->set_filenames(array(
    'body' => 'Gamma.html',
));

make_jumpbox(append_sid("{$phpbb_root_path}viewforum.$phpEx"));
page_footer();
?>
... because the PHP form data does not transfer to through this "Delta.php" page and into the "Gamma" page.
User avatar
LiquidSpark
Registered User
Posts: 146
Joined: Thu Mar 29, 2007 6:54 pm

Re: Sessions!!!!!

Post by LiquidSpark »

Brf wrote:phpBB php files use an html template as described above. The include of the overall_header.html in that html template is what makes the page "look like" your forum.
In case I wasn't clear in my previous 6 posts, this ^ does not work with my form data PHP file.

I need an alternative, and I need one fast.

EDIT: I found the following documentation, but it doesn't look promising.
3.2.2. Template Variables
The means of transporting data to the template is the use of template variables.. By convention, template variable names are always all-uppercase. Variables output to the user are enclosed in curly braces (e.g. {L_SOME_VARIABLE}) while variables in control structures are used directly.

The naming conventions for template variables are:
  • * Template related variables are prefixed with "T_". These are usually pre-assigned by the phpBB3 core code
    * Variables to be used in control structures or for form actions etc. are prefixed with "S_".
Does this mean that I have to integrate my variables in the main phpBB data, and therefore I cannot use my own form pages?
User avatar
Brf
Support Team Member
Support Team Member
Posts: 53629
Joined: Tue May 10, 2005 7:47 pm
Location: {postrow.POSTER_FROM}

Re: Sessions!!!!!

Post by Brf »

You cannot embed PHP directly into an HTML template using the <?php ?> tags. You would have to use

Code: Select all

<!-- PHP -->

<!-- ENDPHP -->
as detailed in the templating guide on this page:
http://area51.phpbb.com/docs/coding-guidelines.html
User avatar
LiquidSpark
Registered User
Posts: 146
Joined: Thu Mar 29, 2007 6:54 pm

Re: Sessions!!!!!

Post by LiquidSpark »

thanks, that was helpful, but it's still not displaying anything between the content tags. i'll try variations.

EDIT: I went to the board's security settings and turned on PHP in templates, but it still doesn't display the embedded php content.

Any suggestions?

Return to “[3.0.x] MOD Writers Discussion”