I'm getting a site together @ http://www.euneos.org.. Most things are based round the SMF forums (modded slightly).
My problem is this: I'm running a divisions system, and need the ability for registered users to signup to these divisions, to do that, I need to get the user id from the cookie, to auth that user. the Divisions script is @ http://www.euneos.org/divisions.php.
I'd be very grateful if someone could tell me how to properly split the cookie in PHP and grab the ID_MEMBER from it.
Thanks,
TheDoctor
Founder of The Euneos Foundation
Actually, if you just want to grab the ID_MEMBER, use ssi_welcome with no parameters:
just put require('../SSI.php'); at the beginning of your PHP script (right before any other code), and then when you want to get the member id, just assign some variable to ssi_welcome(); and use that variable.
That doesnt work... heres the two files:
divisions.php
<?php
ob_start();
include('/home/euneos.org/www/web/global.php');
PrintHeader();
if($_REQUEST["id"] OR $_REQUEST["name"]) {
$query = mysql_query("SELECT * FROM divisions WHERE id='".$_REQUEST["id"]."' OR shortname='".$_REQUEST["name"]."'");
if(mysql_num_rows($query) == 1) {
$row = mysql_fetch_array($query);
if($_REQUEST["task"] == "Signup") {
include('/home/euneos.org/www/web/divisions/signup.php');
}
elseif($_REQUEST["task"] == "ControlPanel") {
include('/home/euneos.org/www/web/divisions/index.php');
}
else {
ShowDiv($row["id"]);
}
}
else {
PrintError('Invalid Division ID or Name');
}
}
else {
ShowDiv('1');
}
function ShowDiv($id) {
$div_query = mysql_query("SELECT * FROM divisions WHERE id='".$id."'");
$div_row = mysql_fetch_array($div_query);
echo "<h2 align=\"center\"><font color=\"".$div_row["color"]."\">".$div_row["name"]."</font></h2>\n\n";
echo "<center><b>".$div_row["description"]."</b></center>\n";
echo "<ul type=\"disc\">\n";
echo " <li><b>Division Information</b></li>\n";
echo " <ul type=\"circle\">\n";
echo " <li><b>Join Rank:</b> ".GetRank($div_row["joinrank"])."</li>\n";
if($div_row["website"] != null) {
echo " <li><b>Website:</b> <a href=\"".$div_row["website"]."\">".$div_row["name"]."</a></li>\n";
}
if($div_row["joinstatus"] == 1) {
echo " <li><b>Join Status:</b> Closed for recruiting</li>\n";
}
elseif($div_row["joinstatus"] == 2) {
echo " <li><b>Join Status:</b> <a href=\"/divisions.php?id=".$div_row["id"]."&task=Signup\">Apply for this Division</a></li>\n";
}
elseif($div_row["joinstatus"] == 3) {
echo " <li><b>Join Status:</b> <a href=\"/divisions.php?id=".$div_row["id"]."&task=Signup\">Open for recruiting</a></li>\n";
}
if($div_row["parent"] > 0) {
$p_query = mysql_query("SELECT * FROM divisions WHERE id='".$div_row["parent"]."'");
$p_row = mysql_fetch_array($p_query);
echo " <li><b>Up:</b> <a href=\"/divisions.php?id=".$div_row["parent"]."\"><font color=\"".$p_row["color"]."\">".$p_row["name"]."</font></a></li>\n";
}
echo " </ul>\n";
echo "</ul>\n";
echo "<ul type=\"disc\">\n";
echo " <li><b>Division Management</b></li>\n";
echo " <ul type=\"circle\">\n";
if($div_row["leader1"] > 0) {
echo " <li><b>Leader:</b> ".GetNameRank($div_row["leader1"])."</li>\n";
if($div_row["leader2"]) {
echo " <li><b>Leader:</b> ".GetNameRank($div_row["leader2"])."</li>\n";
}
if($div_row["deputyleader1"]) {
echo " <li><b>Deputy Leader:</b> ".GetNameRank($div_row["deputyleader1"])."</li>\n";
}
if($div_row["deputyleader2"]) {
echo " <li><b>Deputy Leader:</b> ".GetNameRank($div_row["deputyleader2"])."</li>\n";
}
if($div_row["deputyleader2"]) {
echo " <li><b>Deputy Leader:</b> ".GetNameRank($div_row["deputyleader3"])."</li>\n";
}
}
else {
echo " <li><b>Leader:</b> Open</li>\n";
}
echo " </ul>\n";
echo "</ul>\n\n";
$nm_query = mysql_query("SELECT * FROM smf_members WHERE divisionID='".$id."'");
if(mysql_num_rows($nm_query) > 0) {
$nm_row = mysql_fetch_array($nm_query);
if($nm_row["ID_MEMBER"] == $div_row["leader1"]) {
}
elseif($nm_row["ID_MEMBER"] == $div_row["leader2"]) {
}
elseif($nm_row["ID_MEMBER"] == $div_row["deputyleader1"]) {
}
elseif($nm_row["ID_MEMBER"] == $div_row["deputyleader2"]) {
}
elseif($nm_row["ID_MEMBER"] == $div_row["deputyleader3"]) {
}
else {
echo "<ul type=\"disc\">\n";
echo " <li><b>Members</b></li>\n";
echo " <ul type=\"circle\">\n";
Members($div_row["id"]);
echo " </ul>\n";
echo "</ul>\n\n";
}
$sub_query = mysql_query("SELECT * FROM divisions WHERE parent='".$id."'");
if(mysql_num_rows($sub_query) > 0) {
echo "<ul type=\"disc\">\n";
echo " <li><b>Sub Divisions</b></li>\n";
echo " <ul type=\"circle\">\n";
SubDivs($div_row["id"]);
echo " </ul>\n";
echo "</ul>\n\n";
}
}
}
function Members($id) {
$mbr_query = mysql_query("SELECT * FROM smf_members WHERE divisionID='".$id."'");
while($mbr_row = mysql_fetch_array($mbr_query)) {
echo " <li>".GetNameRank($mbr_row["ID_MEMBER"])."</li>\n";
}
}
function SubDivs($id) {
$sub_query = mysql_query("SELECT * FROM divisions WHERE parent='".$id."'");
while($sub_row = mysql_fetch_array($sub_query)) {
if($sub_row["leader1"] > 0) {
$ldr = GetNameRank($sub_row["leader1"]);
}
else {
$ldr = "<i>Open</i>";
}
echo " <li><a href=\"/divisions.php?id=".$sub_row["id"]."\"><font color=\"".$sub_row["color"]."\">".$sub_row["name"]."</font></a><font color=\"".$sub_row["color"]."\"> - ".$ldr."</font></li>\n";
}
}
PrintFooter();
ob_flush();
?>
divisions/signup.php
<?php
ob_start();
if($_REQUEST["id"]) {
ShowOpts($_REQUEST["id"]);
}
else {
PrintError('No Division ID Specified');
}
function ShowOpts($id) {
$id_query = mysql_query("SELECT * FROM divisions WHERE id='".$id."'");
$id_row = mysql_fetch_array($id_query);
$u_query = mysql_query("SELECT * FROM smf_members WHERE ID_MEMBER='".<need id bit here>."'");
if($id_row["joinstatus"] == 0 OR $id_row["joinstatus"] == 1) {
PrintError('This Division is not currently recruiting');
}
else {
}
}
ob_flush();
?>
the divisions script is fine, the SSI.php file is included in global.php, the prob is where the <need id bit here> i need to split the cookie, get the userid as sommat like $id = $_COOKIE['TEF'] for instance. Its so that it sees if theyre logged in, and if that division requires an application, it adds the userid and division id to table divwishlist, from there the Division leader can view that wishlist in divisions/wishlist.php and select who they will admit, and who they will reject, etc.
Hope that sheds a little more light on the problem.
Thanks,
TheDoctor
Founder of The Euneos Foundation
SSI.php fills a global variable - namely, $ID_MEMBER. This is what you want, I expect.
Using the cookie directly is messy imho, because the session could be used for login.
-[Unknown]
Yup, it works now.
i put global $ID_MEMBER; in ShowOpts() and in the query, and it runs fine :)
Thanks guys, very much appreciated.
Thanks,
TheDoctor
Founder of The Euneos Foundation (http://www.euneos.org/)