Jump to content

Recommended Posts

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

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?

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;

?>

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.