session variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tania
Forum Newbie
Posts: 3
Joined: Tue Sep 02, 2014 2:31 am

session variable

Post 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;
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: session variable

Post by requinix »

Did you session_start()? Any errors being recorded anywhere?
tania
Forum Newbie
Posts: 3
Joined: Tue Sep 02, 2014 2:31 am

Re: session variable

Post 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
tania
Forum Newbie
Posts: 3
Joined: Tue Sep 02, 2014 2:31 am

Re: session variable

Post 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
guruparthi
Forum Newbie
Posts: 1
Joined: Tue Jun 24, 2014 4:13 am

Re: session variable

Post 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
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: session variable

Post by Celauran »

Never ever store passwords in session data!
Post Reply