Problems with phpBB on main site...
Hello, I have no problems with my forum, it's using the log in system on the rest of the site.
I run a legal music download site. I want to add a few features though. I did some reasearch and found somewhere on this site what I had to do to enable users to log in through the main part of my site.
You can view my site at http://www.sublimestylee.com/
Use demo for the username and demo2 as the password. For the sake of this post, use the login form on the page, not through the forum.
Here are my problems.
1. When you login through the main site, you have to click to a different page before the login area shows that you have logged in. Don't click on Lyrics or Radio, they either don't exist or are different.
2. No matter what, when you click on the "Contact" page, it shows the login form, even if you are logged in. I think it may have to do with the form for the contact coinciding with the login form.
3. How can I make it so that when you log in or log out from the main site, you get redirected to the page where you logged in or logged out from. Right now I have it set to index.php. Is there some javascript function I could incorporate into phpBB to redirect them back to where they logged in?
4. Lastly, the feature that I really want to incorporate is so that users must be logged in and have x number of posts before they can download. It sounds like it shouldn't be a problem, but read on. I use a download system on my server so I don't give out file names and url's of files.
An example link to a download is http://www.download.sublimestylee.com/download.php?id=77&check=yes
That means, I need to incorporate the "if($userdata['session_logged_in'])" into download.php. I tried using the exact code used on the site to check if a user is logged in and changed the respective paths to the subdomain, but I got all sorts of errors. I think the problem is because the forum is on the sublimestylee.com domain while the files to download and the download.php script is on the subdomain download.sublimestylee.com.
Below is the code I am using on the main site to check if a user is logged in...
<?php
define('IN_PHPBB', true);
$currentFile = $_SERVER["SCRIPT_NAME"];
if($currentFile == "/index.php")
{
$phpbb_root_path = './chat/';
}
else
{
$phpbb_root_path = '../chat/';
}
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii" />
<meta name="verify-v1" content="ZvKQOJOK5na5dA1vrggPu1TqiNkbQLN40hyUi9LtNFg=" />
<link rel="icon" HREF="http://www.sublimestylee.com/page_images/icon.gif" TYPE="image/gif">
<link rel="stylesheet" type="text/css" href="http://www.sublimestylee.com/pages/ss_style.css" >
<link rel="alternate" type="application/rss+xml" title="Sublime Stylee RSS/XML Newsfeed" href="rss.php"/>
<title>Sublime Stylee</title>
<script type="text/javascript" src="http://www.sublimestylee.com/pages/rollover.js">
</script>
<script type="text/javascript">
function popUp(URL)
{
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=480,height=260,left = 340,top = 200');");
}
</script>
</head>
<body>
<div id="page">
<div id="header">
<img src="http://www.sublimestylee.com/page_images/index_01.gif" alt="Sublime Stylee Header">
<div id="horzban">
<?php
CODE FOR BANNER REMOVED, NOT NEEDED
</div>
</div>
<div id="menu_home">
THE MENU LINKS CODE IS HERE, I REMOVED IT BECAUSE IT WASN'T IMPORTANT
</div>
<div id="login_spot" align="center">
<?php
if($userdata['session_logged_in'])
{
//Generate a random greeting message.
$random_number = rand(0,7);
$greeting[0] = "Konnichiwa";
$greeting[1] = "Bonjour";
$greeting[2] = "Hola";
$greeting[3] = "Ciao";
$greeting[4] = "Aloha";
$greeting[5] = "Guten Tag";
$greeting[6] = "Shalom";
$greeting[7] = "Jambo";
echo('<div id="logged_in"><p class=\"logged_in_font\"><b>' . $greeting[$random_number] . ' ' . $userdata['username'] . '</b> | ');
echo('<a href="' . $phpbb_root_path . 'login.' . $phpEx . '?logout=true&sid=' . $userdata['session_id'] . '&redirect=../index.php' . '">Logout</a>');
echo("<br /><br /><b>Number of Posts:</b> " . $userdata["user_posts"] . "<br/><b>Number of Downloads:</b> " . $userdata["total_downloads"] . "<br/><b>MB's Downloaded:</b> " . $userdata["total_mb"] . "</p></div>");
}
else
{
?>
<form action="http://www.sublimestylee.com/chat/login.php" method="post" enctype="multipart/form-data">
<div id="login_font_un">
<input class="searchbox" type="text" name="username" />
</div>
<div id="login_font_pw">
<input class="searchbox" type="password" name="password" />
<input type="hidden" name="redirect" value="../index.php" />
</div>
<div id="login_font_buttons">
<input class="button" type="submit" value="login" name="login" />
<input class="button" type="reset" value="reset" />
<p class="page_font">
<br>
<a href="http://www.sublimestylee.com/chat/profile.php?mode=register">register here</a>
</p>
</div>
</form>
<?php
}
?>
Here is the code I would use on the download.php file...
You can view a copy of the error's I get here, http://www.download.sublimestylee.com/download2.php?id=141&check=yes
Notice how that is download2.php
<?php
define('IN_PHPBB', true);
$phpbb_root_path = 'http://www.download.sublimestylee.com/chat/';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);
//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_INDEX);
init_userprefs($userdata);
//
// End session management
//
if($userdata['session_logged_in'] && ($userdata['user_posts'] >= 5))
{
error_reporting(E_ALL);
if(isset($_GET['id']))
{
include 'library/config.php';
include 'library/opendb.php';
$check = $_GET["check"];
$id = $_GET['id'];
$query = "SELECT name, type, size, path, click_count FROM downloads WHERE id = '$id'";
$dlresult = mysql_query($query) or die('Error, query failed');
if ($check == "yes")
{
$sql = "SELECT * FROM downloads WHERE id='$id'";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result))
{
$count = $row["click_count"];
$newcount = $count + 1;
}
$newsql = "UPDATE downloads SET click_count = $newcount WHERE id = $id";
$newresult = mysql_query($newsql);
list($name, $type, $size, $filePath) = mysql_fetch_array($dlresult);
header("Content-Disposition: attachment; filename=$name");
header("Content-length: $size");
header("Content-type: $type");
readfile($filePath);
include 'library/closedb.php';
exit;
}
}
}
else
{
//DO THIS
}
?>
I played with the download.php code for several hours trying to get it to work, sometimes I would get the Hacking Attempt error. Point is, I never got it to work. If you are able to solve any of my 4 issues above, I cannot thank you enough!
I did post this on phpBB website, but they are lazy and don't like to respond sometimes.
greg posted this at 15:43 — 20th July 2007.
He has: 1,581 posts
Joined: Nov 2005
1. When you login through the main site, you have to click to a different page before the login area shows that you have logged in.
REPLY:
without looking at the code, I would take a guess that the bit that displays either the login form or users details WHEN they are logged in is in the wrong place in your code
so maybe when a user logs in, the page refreshes but that login area doesnt?
the typical mistake are things within a header page (the page that draws all your top navigation links etc) gets drawn BEFORE the code has determined IF something
in your case the top box with the user login form or users details if logged in will be drawn by the header page BEFORE the code in the index.php has had chance to determine if the user is logged in or not
They are just guesses, the best way to find out is to trace though your code thinking in your head what happens. Find where that login form is in your code editor and imagine filling it out, then where does the code go next, or what does it do?
follow through your code all the way and you should find why it needs a second page load to accept a user is logged in
(maybe its on the same page within a if/else...if so then the page obviously isnt reloaded, and the user will only be shown as logged in when the user clicks another (or the same) page and the if/else statement is re-read by the server again)
And of course have a good look at the code in your login.php file and wherever the code is that checks if a user is logged in or not
my guess would be the user goes to login.php, the info they put in the form matches a user and logs them in, BUT the code that checks if they are logged in or not IS NOT executed from their journey from login.php back to index.php (or whatever page it redirects them to)
2. No matter what, when you click on the "Contact" page, it shows the login form, even if you are logged in.
REPLY:
It actually shows the contact form too, so I would check the page form.php and make sure it is correctly identifying a users is logged in, and check the code on that page that displays [either] the login form [or] the users details (the box in the upper left hand side)
Coupled with number 1, you definitely need to investigate your code that determines when a user is logged in or not
3. How can I make it so that when you log in or log out from the main site, you get redirected to the page where you logged in or logged out from.
REPLY:
I'm not 100% sure what you want, but within your form in the upper left hand box that logs users in, you have a form
when username and password are filled in, and the login button pressed, the user is taken to login.php with the info from that form POSTED
So I would imagine in login.php page, you could use an if/else to send users wherever you want
if login successful then goto page
else goto page (or stay at same page and echo "invalid login")
If you want to send them back to where they came from
you can get the URL info in php with code, so you could put that info in the form and post it to your login.php page, so when login == successful then send them to the page using the URL info you posted in the login form
whatever page your user is on, when they click the login form, the URL info that will be psted will be the current page they are on
thus sending them back to where they came from
(there are some nifty php coders on this site though, who might have a simpler solution)
4. Lastly, the feature that I really want to incorporate is so that users must be logged in and have x number of posts before they can download.
REPLY:
As it's a phpbb forum, and their posts are recorded in a database, then you can get individual users post count from their individual id
so you want to be making code that checks the current logged in users database row for how many posts they have had, either by counting all the rows for their post inputs, or even create a new row that counts them for you
then
if ( $post_count < $x_amount) { echo "sorry not enough posts" } etc
else { goto download }
have a look at this (Control access to view / post in forums based on a user's post count.)
http://www.phpbb.com/community/viewtopic.php?t=471142&sid=7d1ad6a80ecd55a1e6688583acaaa513
it isnt exactly what you are wanting, but it should give you some ideas as to how to check users post counts in phpbb, then define an if/else clause, of course you will change yours to allow a link if they have the minimum posts, or issue a statement reminding/informing them they have to have x posts before downloading
one thing I will say about number 4.
Be careful of limiting people from things until x posts in a forum
many people will just post rubbish to hit their target.
not neccesarily spam, but nonetheless rubbish that may not be filling your forum with meaningful topics.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.