SkyRanger Posted April 20, 2007 Share Posted April 20, 2007 Not sure how to do this. This is what I have: include_once("config.php"); // Check user logged in already: checkLoggedIn("yes"); doCSS(); print("Welcome to the members page <b>".$_SESSION["login"]."</b><br>\n"); print("<a href=\"logout.php"."\">Logout</a>"); I need to figure out some way to add it to this: function main() { php/mysql code here } function board { more php/mysql code here } switch($board) { default: main(); break; case "board"; board($oid); break; } How would I get the top code to work in the functions? I keep getting errors like: Notice: Undefined variable: board Quote Link to comment Share on other sites More sharing options...
trq Posted April 20, 2007 Share Posted April 20, 2007 Sorry, but none of that code makes much sense. Quote Link to comment Share on other sites More sharing options...
Moon-Man.net Posted April 20, 2007 Share Posted April 20, 2007 Any variables that are in a function, are just that. Only in the function. unless they are specifically passed to it. to get a variable from out of the function, use this. function test($var){ global $var1 echo $var1 echo $var } I don't need to do it for $var, because it was passed to the function when called. Hope that helps. -- NAthan Quote Link to comment Share on other sites More sharing options...
alecks Posted April 20, 2007 Share Posted April 20, 2007 Umm... not sure what you are trying to do here, but I am guessing that you want to have a forum, and in this forum separate boards. I am going to spell this out as detailed as possible. Ex, the forum structure: YOUR FORUM (1) General (2) Another (3) Another Board If the URL is "index.php", then it would show main(), which is just a listing of these boards. If $oid is set ("index.php?$board=board&oid="), then it would do board($oid), and board() would display the forum board that corresponds to $oid. Ex. If $oid was 1 then based on the example forum structure above board() would display the General forum. Am I right so far? You really don't need the $board variable, based on what I'm seeing. Your code, based on this, may look something like this in the end: include_once("config.php"); function main() { global $whatever_vars_from_config_you_need if (checkLoggedIn("yes")){ doCSS(); print("Welcome to the members page <b>".$_SESSION["login"]."</b><br>\n"); print("<a href=\"logout.php"."\">Logout</a>"); }else{ print("You are not logged in."); } } function board($oid) { // Code to display the board that corresponds with $oid, probably from a database. Also, tests (checkLoggedIn("yes")) to see if they are logged in or not. } switch($board) { default: main(); break; case "board"; board($oid); break; } [/cODE] Sorry if I can't be more help, but you are being pretty vague :/ Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted April 20, 2007 Author Share Posted April 20, 2007 Ok, I will try to explain this a little better. What I am trying to do is: 1) Main PHP Page with Login 2) postit board I am currently working on with is the //code placed on the top of all php pages you want secure include_once("config.php"); // Check user logged in already: checkLoggedIn("yes"); doCSS(); print("Welcome to the members page <b>".$_SESSION["login"]."</b><br>\n"); print("Your password is: <b>".$_SESSION["password"]."</b><br>\n"); print("<a href=\"logout.php"."\">Logout</a>"); When the user logs in they are then sent to for example the page below: office.php which would be http://domain.com/office.php function main(){ $query = "SELECT users.*, office.* FROM users, office where id = omid ORDER BY `oid` DESC"; $result = mysql_query($query) or die ("Query failed"); //let's get the number of rows in our result so we can use it in a for loop $numofrows = mysql_num_rows($result); .... stuff pulled from mysql with a link to ?board=board&oid=".$row['oid']."\"> } function board($oid){ more stuff here pulled from mysql with oid='$oid' } switch($board) { default: main(); break; case "board"; board($oid); break; } This is the config.php file error_reporting(E_ALL); include_once("functions.php"); session_register("login"); session_register("password"); session_register("loggedIn"); $messages=array(); include "inc/dbinfo.inc.php"; $dbhost="$dblocation"; $dbuser="$dbusername"; $dbpass="$dbpassword"; $dbname="$dbname"; connectToDB(); What I need is the top block of code to be inserted somehow into the function main() and function($oid) board and all the other function whatever() that I have in the script. I hope that is a little more clearer on what I am trying to do. Quote Link to comment Share on other sites More sharing options...
SkyRanger Posted April 20, 2007 Author Share Posted April 20, 2007 This was becoming too complicated for myself because I an still a really big noob to php so I decided to separate the file into separate pages till I learn more. Thanks all for all of your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.