Passing value to next page via session

How to pass variable $nameID to the secondpage.php? I don’t want to pass it through url because I want url to be clean.

Probably session is best solution but now I have a problem with the following code:
firstpage.php
<html>
<?php
session_start();
$nameID=…(I get name from database)
$name=…(I get name from database)
$_SESSION[‘nameID’] = $nameID;
echo “<a href=‘secondpage.php/$name’>$name</a>”;
?>
</html>

secondpage.php
<?php
session_start();
echo $_SESSION[‘nameID’];
?>

I get error message for this:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at E:\xampp\htdocs\firstpage.php:2) in E:\xampp\htdocs\firstpage.php on line 3

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at E:\xampp\htdocs\firstpage.php:2) in E:\xampp\htdocs\firstpage.php on line 3
ernest

Please tell me what is wrong here.

what if browser blocks cookies?

Make sure you’re not outputting anything to the browser before session_start(). If you’re sure that there’s no characters before <?php tag and you’re not outputting anything from PHP then you’re probably saving the files as UTF-8 with BOM in which case you need to change your editor’s settings to not add BOM to the beginning of UTF-8 files.

tnx, you were right. I shouldn’t write
<html>
<?php
session_start();

but
<?php session_start() ?>
<html>
<?php

That’s right.

Use [ php ] tags when posting code here - it makes it a lot easier to read!

Keep in mind the session method will break and confuse your users if they happen to have multiple browser windows open at the same time. It also fails if they have cookies disabled(unless you pass the session id through the url as a backup method).

The proper way is to pass this info in the url. You can use url rewriting if you object to using the ? character in your urls.