spires Posted April 21, 2009 Share Posted April 21, 2009 Hi guys. I'm trying to create a session (session_register(usName)). But for some reason the session is being created, but when I try to echo the session, it's empty? <?PHP session_start(); include("../dbconnect.php"); include("../Library/head.php"); if(session_is_registered(usName)) { header("Location:cms.php"); } // If Submit if (isset($_POST['submit1'])) { if ($_POST['user1']==''){ $star1 = '<span class="title_red_11_bold">*</span>'; } if ($_POST['pass1']==''){ $star2 = '<span class="title_red_11_bold">*</span>'; } if ($_POST['user1']=='' || $_POST['pass1']=='') { $sent1 = '<span class="title_red_11_bold">Sorry, but all areas marked with * must be completed</span>'; $user1=$_POST['user1']; $pass1=$_POST['pass1']; }else{ $user1=$_POST['user1']; $pass1=$_POST['pass1']; $sql="SELECT * FROM csv_login WHERE login_username='$user1' && login_password='$pass1'"; $result = mysql_query($sql); $count = mysql_num_rows($result); $row = mysql_fetch_array($result); $usName = $row['login_username']; if($count==1){ session_register(usName); header("Location:cms.php"); } else { $noinput = '<div class="title_red_11_bold">Your details are incorrect Please try again</div>'; } } } ?> following page - cms.php <?PHP session_start(); include("../dbconnect.php"); include("../Library/head.php"); $usName = $_SESSION["usName"]; echo 'hello '.$usName; ?> Thanks for your help Link to comment https://forums.phpfreaks.com/topic/155014-can-anyone-see-what-im-doing-wrong/ Share on other sites More sharing options...
jesushax Posted April 21, 2009 Share Posted April 21, 2009 have you tried echoing usName before you create the session $usName = $row['login_username']; echo $usName; see if that returns a result Link to comment https://forums.phpfreaks.com/topic/155014-can-anyone-see-what-im-doing-wrong/#findComment-815313 Share on other sites More sharing options...
spires Posted April 21, 2009 Author Share Posted April 21, 2009 I just tried it. It does return the result for $usName. Any other ideas? Link to comment https://forums.phpfreaks.com/topic/155014-can-anyone-see-what-im-doing-wrong/#findComment-815322 Share on other sites More sharing options...
jesushax Posted April 21, 2009 Share Posted April 21, 2009 ok next echo the result for $count your session relies on $count being 1 so lets see if its not 1 Link to comment https://forums.phpfreaks.com/topic/155014-can-anyone-see-what-im-doing-wrong/#findComment-815323 Share on other sites More sharing options...
spires Posted April 21, 2009 Author Share Posted April 21, 2009 Yep, $count is = 1 The session is being created. I know this because, if I go back to the login page I am redirected back to the cms.php page. see: if(session_is_registered(usName)) { header("Location:cms.php"); } Thanks for your help. Any more ideas? Link to comment https://forums.phpfreaks.com/topic/155014-can-anyone-see-what-im-doing-wrong/#findComment-815329 Share on other sites More sharing options...
jesushax Posted April 21, 2009 Share Posted April 21, 2009 ok for arguments sake just try changing the following <?php if(session_is_registered(usName)) { //change to if(!empty($_SESSION("usName"))) { if($count==1){ session_register(usName); //change to if($count==1){ $_SESSION["usName"] = $usName; ?> Link to comment https://forums.phpfreaks.com/topic/155014-can-anyone-see-what-im-doing-wrong/#findComment-815338 Share on other sites More sharing options...
kenrbnsn Posted April 21, 2009 Share Posted April 21, 2009 The functions session_is_registered and session_register will be depreciated in PHP v5.3.0 and should not be used. They will be removed in v6. Use: <?php session_start(); $_SESSION['var'] = "some value"; // sets the session variable if (isset($_SESSION['var'])) // tests to see if it's set echo 'ok'; ?> Ken Link to comment https://forums.phpfreaks.com/topic/155014-can-anyone-see-what-im-doing-wrong/#findComment-815346 Share on other sites More sharing options...
spires Posted April 21, 2009 Author Share Posted April 21, 2009 OK, just tried it. Exactly the same. On the cms.php where i'm echoing out the $_SESSION['usName']; it come out blank. Link to comment https://forums.phpfreaks.com/topic/155014-can-anyone-see-what-im-doing-wrong/#findComment-815355 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.