Page 1 of 1
Session problems
Posted: Fri Jan 30, 2004 4:57 am
by Luis Almeida
I have this two pages
test3.php
Code: Select all
<?php
session_start();
session_register("valor");
$valor=session_id();
echo $valor;
echo '<br><br><a href="test4.php">next page</a>';
?>
and
test4.php
Code: Select all
<?php
session_start();
echo $valor;
?>
Shouldn´t it write the same value for "$valor" on page test4.php as on page test3.php
this is because on page test3.php it returns (for example):
1e5aa925c880a752d8a8a5f52aea5434
next page
And when I click "next page" Link it returns nothing
Can anyone help me please
thanks in advance
Posted: Fri Jan 30, 2004 5:03 am
by twigletmac
You shouldn't be using session_register() - it's a deprecated function which does not work with register_globals off.
Instead try:
test3.php
Code: Select all
<?php
session_start();
$_SESSION['valor'] = session_id();
echo $_SESSION['valor'];
?>
<p><a href="test4.php">Test Session</a></p>
and
test4.php
Code: Select all
<?php
session_start();
echo '<pre>';
print_r($_SESSION);
echo '</pre>';
?>
Mac
Posted: Fri Jan 30, 2004 6:04 am
by Luis Almeida
It Worked jut fine
thank´s twigletmac
But now there is another question
Does it mean that if, for example, I need to make an aritmethic operation on a session variable like :
Code: Select all
<?php
session_start();
$_SESSION['valor'] =10;
$_SESSION['valor'] =$_SESSION['valor']+1;
?>
Do I have to use always the '$_SESSION' to refer to a session variable???
Posted: Fri Jan 30, 2004 6:29 am
by twigletmac
For the example you gave you could rewrite the code:
Code: Select all
$_SESSION['valor'] =$_SESSION['valor']+1;
as
which saves a bit of typing.
If, however, you need to do a lot of work with a session variable you can easily define it as a new variable before you start and then when you're finished with the calculations set the resulting value back to the session variable, e.g.:
Code: Select all
<?php
session_start();
// create the temporary variable
$valor = $_SESSION['valor'];
// code working with $valor
// finished calculations set $_SESSION['valor'] to new value
$_SESSION['valor'] = $valor;
?>
Mac
Session problems
Posted: Fri Jan 30, 2004 8:11 am
by Luis Almeida
Thank's a lot
You have been a great help