2

Possible Duplicate:
How to fix the session_register() DEPRECATED problem?

I tried the following code out in firefox and it gave me an error whats wrong?

<?php 
  session_start(); 
  $username = "Eric"; 
  session_register("username");
?>
<h2>Mijn naam is <?php echo $_SESSION["username"];?></h2>
Community
  • 1
  • 1
jan
  • 147
  • 1
  • 5
  • 14

3 Answers3

5

This function has been DEPRECATED as of PHP 5.3.0. Relying on this feature is highly discouraged.

try like this:

session_start();
$_SESSION['username'] = $username;

then (in other page):

session_start();
echo $_SESSION['username'];
John Flatness
  • 30,929
  • 5
  • 77
  • 80
Aivis
  • 66
  • 1
2

session_register() is deprecated and should not be used in any new code. use:

<?php

session_start();
$_SESSION['username'] = 'Eric';

instead.

Marc B
  • 348,685
  • 41
  • 398
  • 480
0

Make sure there is no white space before <?php

Clint C.
  • 658
  • 13
  • 31