html - How to display sessions information using php -


i trying display session information username, user login through login page, session has capture user entered username , should display in page. below have tried php script, not echoing username, kindly check in script errors, in advance.

<?php      session_start();      $_session['test']= $_post['myusername'];     $name= $_session['test']; echo $name; ?>      <form action="login.php" method="post"> <p>username</p>  <input name="myusername" type="text" id="myusername" required> <p>password</p> <input name="mypassword" type="password" id="mypassword"required></br> <button><img src="http://icons.iconarchive.com/icons/webiconset/application/32/register-icon.png"  /></button> </form> 

login.php

output getting , going next page without displaying user name.

you can't access session data until after call session_start(). first if statement unnecessary , problematic can't check if session variable exists until after start session. also, make sure session_start() called @ top of every page wish use sessions.

<?php session_start();  $_session['test']= $_post['myusername']; 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -