balkan7 Posted March 6, 2009 Share Posted March 6, 2009 hi guys, I tested the code on my localhost and it works, but when I tested on my site that will not show me $_SESSION[ 'username']; login.php <?php session_start(); session_destroy(); $show = ""; if (isset($_POST['login'])) { $username = $_POST['username']; $md5_password = md5($_POST['password']); $result = mysql_query("SELECT * FROM admin WHERE username='$username' AND password='$md5_password'"); if(dbrows($rezultat) != 0){ session_register("username"); header("location:admin/index.php"); exit; } else { $show = $lang['login-005']; } } ?> admin/index.php <?php session_start(); if (!session_is_registered("username")) { header("location:../index.php"); } echo $_SESSION[ 'username']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/148283-solved-working-with-sessions/ Share on other sites More sharing options...
redarrow Posted March 6, 2009 Share Posted March 6, 2009 use a session like $_SESSION['username']=$what_ever; <<<< new way. session_register("username"); <<<< old way mate. Quote Link to comment https://forums.phpfreaks.com/topic/148283-solved-working-with-sessions/#findComment-778444 Share on other sites More sharing options...
redarrow Posted March 6, 2009 Share Posted March 6, 2009 why you got this >>session_destroy(); afther session_start() your need another session_start() afther the session_destroy. in fact my posted replies is correct but , you should rely unset($_SESSION['session_name']) to kill the session needs killing, but session_start kills all sessions. <?php ob_start(); session_start(); session_destroy(); session_start(); $show = ""; if (isset($_POST['login'])) { $username = $_POST['username']; $md5_password = md5($_POST['password']); $result = mysql_query("SELECT * FROM admin WHERE username='$username' AND password='$md5_password'"); if(dbrows($rezultat) != 0){ $_SESSION['username']=$username; header("location:admin/index.php"); exit; } else { $show = $lang['login-005']; } } ob_flush(); ?> <?php session_start(); if (! $_SESSION['username']) { header("location:../index.php"); } echo $_SESSION[ 'username']; ?> Quote Link to comment https://forums.phpfreaks.com/topic/148283-solved-working-with-sessions/#findComment-778446 Share on other sites More sharing options...
balkan7 Posted March 6, 2009 Author Share Posted March 6, 2009 yes this working after session_destroy(); add new session_start(); thx anyway... Quote Link to comment https://forums.phpfreaks.com/topic/148283-solved-working-with-sessions/#findComment-778450 Share on other sites More sharing options...
Maq Posted March 6, 2009 Share Posted March 6, 2009 Do you have different versions of PHP? session_is_registered has been deprecated in recent versions of PHP. You have to use isset if (!isset($_SESSION['username'])) { header("location: ../index.php"); } else { echo $_SESSION['username']; } Quote Link to comment https://forums.phpfreaks.com/topic/148283-solved-working-with-sessions/#findComment-778462 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.