Error retrieving session variables

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
feiticeir0
Forum Newbie
Posts: 8
Joined: Tue Nov 05, 2002 1:33 pm
Location: Castelo Branco, Portugal

Error retrieving session variables

Post by feiticeir0 »

Hi,

i'm developing a kind of a project in school, and i need to pass variables from one page to another.

i've tried to do this, passing the session to the other page

<td width="15%"><a href="alterar.php?PHPSESSID=<?php $HTTP_SESSION_VARS["idempregado"]?>">Alterar</a></td></tr>

the problem is that, in the other page,
i got the same value. the variables are not the same, the value is not the same, but the result is the same.

i register the variable that i want to pass as a session variable

if ($_POST[escolha]) {
$idempregado = $_POST[idempregado];
session_register ("idempregado");
ver_caracteristicas ($idempregado);

the problem is that i get the same value for the two variables

$var = $_SESSION[idempregado];
$var2 = $_SESSION[idadministrador];


how to do ?

regards
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

So where are you getting the $var2 = $_SESSION[idadministrador];


You should just be able to do

Code: Select all

<?php
session_register ("idempregado", "idadministrador"); 


?>
And then on every page have the session_start(); and you can pass that information along.

I have a pretty long one for one of my sites.

Code: Select all

<?php

   session_register("valid_user", "user","email", "url", "twgs", "level", "id", "sitename", "canpost");


?>
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

just being picky here, but its good practice to use single quotes when define $_SESSION and $_POST variables, eg:

$_POST['Whatever'] instead of $_POST[Whatever]
$_SESSION['Likewise']

:lol:
Post Reply