• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

PHP Question: How do I link the forums to other part of the site?

purbeast0

No Lifer
Basically I want to make it so that the user cannot post comments on the site unless they are logged into the forum. I am not really sure how to do this, although I've heard recommendations on using sessions, however I cannot really get more than that.

I just want to be able to check from the main page if the user is signed into the forums currently, and if so, it'll allow them to post. I basically just need to know what to put inside the "if login" type statement. I'm using PHPBB btw ...

If you know how to do this, or if there is an article on this already, please let me know, thanks!
 
You can do what you want with sessions. Basically you use the start_session() call to start a session, then have the user type in their username and password. Do your verification checks and if they pass, store a boolean or something in a session variable to keep track of whether or not a user is logged in ($_SESSION['logged_in'] = true). Now on any page you want a user to be logged in, do a session_start() to resume the session, and do something like this:

$logged_in = $_SESSION['logged_in'];

if ($logged_in)
// yay
else
echo "You must log in to use this feature";

Something like that. Check out PHP's Session manual for more info. It's quite simple really, you'll just basically need the session_start() function and then store variables you wish to keep track of in the $_SESSION array.
 
Is
<?php
// standard hack prevent
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
if ($userdata['user_id']<=0) {
redirect($phpbb_root_path . 'login.'.$phpEx.'?redirect=mypage.'.$phpEx, true);
}
at the very top of your page, before any HTML?
 
Originally posted by: LoKe
Is
<?php
// standard hack prevent
define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
if ($userdata['user_id']<=0) {
redirect($phpbb_root_path . 'login.'.$phpEx.'?redirect=mypage.'.$phpEx, true);
}
at the very top of your page, before any HTML?

no, it's not. is thats what's causing this problem?
 
damn so now when I include the file at the top before any HTML, for some reason it just doesn't display the page. It always displays the page like it's mypage.com/index.php ... and never acts like any variables are being passed into the url (like it should go to mypage.com/index.php?system=ps2&id=23 or something, but it's not getting any of those variables when I include the common.php file at the top)

any ideas?
 
It's best to declare all your variables at the top of the page. So, declare your variables at the top of the page, before that code. Can you post the code for the entire page?
 
Originally posted by: LoKe
It's best to declare all your variables at the top of the page. So, declare your variables at the top of the page, before that code. Can you post the code for the entire page?

well the variables are being passed in via links on the page. I can't really paste the whole code right here because it is basically my whole website heh, and I don't want to put the source out there 😛.

could the common.php file be using some of the same variable names that i'm using, causing it to screw up?
 
Ah okay so I figured something out ...

Once I load up the common.php file, for some reason, a the variables that are being passed in are lost. So now I set a temp one before the include call, then I set the names back to the temp ones, and now it will go to the rigth pages based on the variable names.

howver i am still getting these warnings ...

Warning: Cannot modify header information - headers already sent by (output started at /public_html/index.php:83) inpublic_html/forums/includes/sessions.php on line 254

Warning: Cannot modify header information - headers already sent by (output started at public_html/index.php:83) in /public_html/forums/includes/sessions.php on line 255

line 83 on index.php is some HTML code, and it's not the first part the HTML is outputting to the screen.

you have any idea what this is now heh? I'm SSSOOO close!

EDIT:

also, line 254 and 254 in sessions.php are the following:

setcookie($cookiename . '_data', serialize($sessiondata), $current_time + 31536000, $cookiepath, $cookiedomain, $cookiesecure);
setcookie($cookiename . '_sid', $session_id, 0, $cookiepath, $cookiedomain, $cookiesecure);

EDIT2:

woohoo finally got it!
 
Originally posted by: purbeast0
I can't really paste the whole code right here because it is basically my whole website heh, and I don't want to put the source out there 😛.
Phpbb is gpl'ed so you're kinda obligated to share it no? Although I guess you wouldn't technically be redistributing if it stays server-side 😛
 
Originally posted by: kamper
Originally posted by: purbeast0
I can't really paste the whole code right here because it is basically my whole website heh, and I don't want to put the source out there 😛.
Phpbb is gpl'ed so you're kinda obligated to share it no? Although I guess you wouldn't technically be redistributing if it stays server-side 😛

I was talking about the code I am writing where I am making these calls heh, not the actual phpBB code 😛

anyways, I fixed the problem. It had to do with the session_pagestart() function being called after some HTML code had already been displayed, so I moved it up to the top part of the page (whereas before it was in the if block where I'm seeing if they are logged in or not) and now all is good 🙂
 
Originally posted by: purbeast0
I was talking about the code I am writing where I am making these calls heh, not the actual phpBB code 😛
Sounds like a derivative work to me. But I'm just being pedantic...
 
Back
Top