passing values

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
cmdo
Forum Newbie
Posts: 13
Joined: Wed Nov 30, 2011 2:04 pm

passing values

Post by cmdo »

Hi all,
I'm new around here.
What I'm trying to do is passing values from login.php to home.php.
Where's my login.php code:

Code: Select all

<?php
	@mysql_connect("localhost", "root", "root") or die("Conexão falhou");
	mysql_select_db('boleias');
	
	//$cadastrar = $_POST['registar'];
	$login = $_POST['login'];
	
	$username = ($_POST['log']);
	$password = ($_POST['pwd']);
	$password_enc = hash("sha512",$_POST['pwd']);
	
	if ($login!='')
	{
		$busca = mysql_query("SELECT username,password FROM users WHERE username='$username' and password='$password_enc'");		
		if (mysql_num_rows($busca)==1)
		{
			session_start();
			$_SESSION['username'] = $username;
			$linha = mysql_fetch_array($busca);
			echo "Hello world! <br />"; 		
			echo "Usuário " .$username. " logado.";
			header('location:home.php');
			
		} else {
			echo "Usuário inexistente ou senha incorreta.";
			
		}
	}
?>
How can I pass the username value into home.php?
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: passing values

Post by AbraCadaver »

If you have session_start() in home.php then you can already access it with $_SESSION['username'].
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
cmdo
Forum Newbie
Posts: 13
Joined: Wed Nov 30, 2011 2:04 pm

Re: passing values

Post by cmdo »

Perfect!!
Thanks a lot :D
Post Reply