grandman Posted December 9, 2008 Share Posted December 9, 2008 Hell, I have a problem with the SESSION FUNCTION. I'm trying to pass a SESSION Variable (username) from the login file located in directory "A" to a file located in directory "E", given a directory structure: A,B,C,D,E. I can't find how to check this, I've d tried print command but it wont work, this is a small snippet from the start of the script: <?php if(!session_id()) session_start(); if (session_is_registered); $user = ($_SESSION['username']); print ($user); ?> Not sure if this is correct, never used session before. This is for my sites members area, I had used a DB access, but really need to make sure I have the log-on member, so I am trying to use session. DG Link to comment https://forums.phpfreaks.com/topic/136228-session/ Share on other sites More sharing options...
premiso Posted December 9, 2008 Share Posted December 9, 2008 [ code ] is your friend. <?php session_start(); if (isset($_SESSION['username'])) $user = $_SESSION['username']; else $user = ""; print ($user); ?> Should work. You do not need the extras of session_id and session_is_registered, the above does that for you. Link to comment https://forums.phpfreaks.com/topic/136228-session/#findComment-710630 Share on other sites More sharing options...
grandman Posted December 9, 2008 Author Share Posted December 9, 2008 [ code ] is your friend. <?php session_start(); if (isset($_SESSION['username'])) $user = $_SESSION['username']; else $user = ""; print ($user); ?> Should work. You do not need the extras of session_id and session_is_registered, the above does that for you. Am I misunderstanding this totally? This is the script I was using: <?php ob_start(); $Database = mysql_connect("localhost", "vars", "vars"); mysql_select_db("vars"); $fields = mysql_query("SELECT * FROM users"); $Username = mysql_result($fields,0,"username"); $dirname = $Username; $filename = "on/cont/" . "$dirname"; if (file_exists($filename)) { header ( "Location: " . "$filename" . "$dirname"); } else { mkdir("on/cont/ " . "$dirname", 0777); echo "welcome " . "$dirname" . "Your Area Is Being created."; } ob_end_flush(); ?> What I'm trying to do is replace the DB input with a SESSION Variable, as I need to make sure I have the right user. This is run when the user logs-in. So if I run the code snippet you put up should it print the user name I'm using? DG Link to comment https://forums.phpfreaks.com/topic/136228-session/#findComment-710671 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.