troubleshooting Question

i need urgent help to print $_SESSION['username'] beside the photo on top right of the page

Avatar of AHMED SAMY
AHMED SAMYFlag for Egypt asked on
PHP
6 Comments1 Solution126 ViewsLast Modified:
i need to call session name in all pages

please if you can improve this code to be secure help!!!!!

please correct cookie code it is not working

note: my hosting godaddy , php 5.6

i am using check.php to check login and redirect to index.php again
<?php

session_start();

class mysql{
	
	private $localhost="localhost";
	private $db_users="****";
	private $db_password="*****";
	private $db_name="*****";

	function __construct(){
		
	mysql_connect($this->localhost,$this->db_users,$this->db_password);
	mysql_select_db($this->db_name);
		}
	
	function sql(){
		
		$username=$_POST['username'];
		$password=$_POST['password'];
		
		$sql="SELECT * FROM users WHERE username='$username' AND password='$password'";
		
		mysql_query("set character_set_server='utf8'");
		mysql_query("set names 'utf8'");

		$query=mysql_query($sql);
		$num=mysql_num_rows($query);
		
		if($num==1){
			$_SESSION['username']="username";
			$_SESSION['password']="password";
			
			//remember me
			@$remember_me=$_POST['rememberme'];
			if($remember_me==1){
			$cook_name="acpauth";
			$time=time()+3600*24*1000 ;//1000 days
			setcookie($cook_name,'usr='.$username.'&hash='.$password,$time);
			}
			
		header("location:packages.php");
		
			}
			else{
				echo "wrong password or username !!!";
			}
			
	}
}
$use=new mysql;
$use->sql();
?>
ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 6 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 6 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros