Hi, I am trying to fetch username from session variable of one php page to another php page.

This below code fetch username from login page

    $uname = $_GET['uname'];


?>.... //Remaining Code

When I click submit button to go to my next php page I want the same username to be dispalyed again.
How can I achieve this?

First store the username in the session variable.

// sanitize/validate first
$_SESSION[$uname] = $uname;

On other pages (within the same session) it will be available to your scripts:

$uname = $_SESSION[$uname];

provided that you used the session_start() (always put it on top of your script).

And sanitize the user input first using appropriate method depending on where are you using the data (database, email, html, url, javascript...).

Thank You!! Its Working..
added session_start().

Cool. If this answers your question please mark the thread as solved. Happy coding.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.