0

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
<?php

    $uname = $_GET['uname'];


@session_start();
if($_SESSION[$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?

2
Contributors
3
Replies
11
Views
3 Years
Discussion Span
Last Post by broj1
1

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...).

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.