0

I want to send some values with php sessions through the current page(eg.php) to another page(a.php). But i cannot make it because some error. just like

"Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\eg.php:6) in C:\xampp\htdocs\eg.php on line 14"

How to resolve it?

My eg.php code

session_start();
define("Username",$name);
define("Password",$password);
$_SESSION['user'] = $name;
echo "<form action =\"\" method = \"post\">";
echo "<input type =\"text\" placeholder =\"Username\" name = \"user\">";
echo "<input type =\"password\" placeholder = \"password\" name = \"pass\">";
echo "<input type =\"submit\" value =\"name\" name = \"btn\">";
echo "</form>";
if(isset($_POST['user']) === true && isset($_POST['pass']) === true){
    $_SESSION['user'] == Username;
    session_write_close();
    header("location:a.php");
}

My a.php code

echo "Welcome ".$_SESSION['user'];
Sidath
  • 98
  • 10

1 Answers1

-1

Make this changes

in eg.php at first line in php code do this

ob_start();

at end/last line in php code do this

ob_end_flush();

in a.php code

at first line use

session_start();

It will work.

Jatin Raikwar
  • 406
  • 5
  • 17