xoligy Posted June 12, 2008 Share Posted June 12, 2008 Session help/advice alotta reading Ok this part has been added after writing all of the code below where I start with “Ok below” sigh is there anyway to add a userlevel system with the current session I have or should I do something similar to what code I have after this code? Basically I want to have some parts restricted by user level where you have your Normal, Mod, Admin users set by either 1, 2, 3 in an array but I can also call and show there either Normal, Mod, Admin. Sorry for writing a lot but I dont have the net at home at the moment so im going to be awfully slow with replying <?php if ($_SESSION['isLogined']){ //echo "LOGINNED"; } else { echo "<br><br><center><font color=red>You are not logged in. Please login.</font></center><br><br><br><br>"; include "bottom.php"; include "right.php"; exit; } ?> Ok below is what i found in a book on how to make a session, what i was thinking is i could incorporate this into my script. But before I go adding loads of code and what not I want to make sure im getting things right and understand things. The header is ok I believe your stating the session and the output buffering (i'll read up on that), now on my database the user_id is just ID well UserDetails->ID so I would change that to just ID yes? And then add user_levels? As for the “Footer” the menu info is actually in my menu.php so I would put that info there yes? After that I kinda got a little lost as I didnt understand the login part properly so will be re-reading that section for the 5th time while you lot reply to this (if you reply that is lol). I have included the login par tof the script but replaced the info with my db stuff and changed a few words mostly mysqli to mysql and $r, $q to $result and $query. If anyone is kind enough to read through all this I do have 1 or 2 more questions about incorporating it in my script Header <?php //Header //Start output buffering and session ob_start; session_start(); ?> Footer → Menu? <?php //Footer //Display links based upon login status if (isset($session['user_id'])) { echo 'links'; //Add links if the user is an admin if ($_SESSION['user_levels']==1){ echo 'admin links'; } } else { //Not logged in echo 'Login/Register'; } ?> <?php //Flush the bufferd output ob_end_flush(); ?> Login <?php //Login part my code isn't present $query = “SELECT 'ID', 'user_level' FROM UserDetails WHERE (email='$email' AND pass=md5('$pass')) AND active IS '1'”; $result = mysql_query ($dbc, $query); if (@mysql_num_rows($result) ==1) { // A match was made. //Register the values and redirect $_SESSION = mysql_fetch_array($result, MYSQL_ASSOC); mysql_free_result($result); mysql_close($dbc); $url = BASE_URL . 'index.php'; //Define the url ob_end_clean(); //Delete the buffer header(“Location: $url”); exit() //quit the script }else{ //No match echo 'Either username and password do not match or your account is not activated'; } }else{ //Something wrong echo 'Something is wrong please try again' } mysql_close($dbc) } //End submit conditions ?> anyway i'll be ehre for the next hour to see any replys otherwise it be on monday Link to comment https://forums.phpfreaks.com/topic/109873-sessions-help-i-dont-understand-them-lotta-text-to-read-o0/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.