Page 1 of 1

session variable

Posted: Tue Sep 02, 2014 2:38 am
by tania

Code: Select all

if($fname && $pas)
{
	include 'connect.php';
	$query=mysql_query("SELECT * FROM user WHERE fname='$fname'");
	$numrows=mysql_num_rows($query);
	if($numrows!==0)
	{
		while($row=mysql_fetch_array($query))
		{
			$dbname=$row['fname'];
			$dbpassword=$row['pas'];
		}
		if(trim($fname)==trim($dbname) && trim($pas)==trim($dbpassword))
		{ 
			
			$_SESSION['user']=$row;
			header('Location: welcome.php');	
		}
on another page when is get the user id or name using <?php $_session['user']['fname'] ?> or something id etc it cant fetch the value to another page, any solution please;

Re: session variable

Posted: Tue Sep 02, 2014 3:48 am
by requinix
Did you session_start()? Any errors being recorded anywhere?

Re: session variable

Posted: Tue Sep 02, 2014 3:55 am
by tania
ya i have staret the session no error come when i post value the form value shows but something when itake from session i does not do work

Re: session variable

Posted: Tue Sep 02, 2014 3:59 am
by tania

Code: Select all

<?php
include 'session.php';
?>
 here the session is included in the page

here is session code
<?php
  $lifetime=600;
  session_start();
  //echo "hello";exit;
  //setcookie(session_name(),session_id(),time()+$lifetime);
  if( !isset($_SESSION['user'])) {
	header("location:index.php");
  }
?>

that i want to display 
 <?php
echo $_SESSION['user']['fname'];
?>
it says that fname is undefined variable

Re: session variable

Posted: Thu Sep 04, 2014 11:42 pm
by guruparthi
Use this code

Code: Select all

<?php
   session_start();
 // after validate form, store username and pwd to session
  $_SESSION['user']=$row['fname'];
  $_SESSION['pwd']=$row['pass'];
// Now the values are stored into session and you can retrieve in anywhere 
?>
 // another page 
<?php
  session_start();
 echo 'welcome'.$_SESSION['user'];
?>
For more details please visit http://www.phponwebsites.com/2014/07/ph ... ation.html

Re: session variable

Posted: Fri Sep 05, 2014 6:40 am
by Celauran
Never ever store passwords in session data!