Jump to content

not being able to display sessions properly


hhex50

Recommended Posts

hi every1 i m new to php.....i ve been trying to figure out whats wrong with the code i wrote...its page counter....it works fine apart frm this that i am not able to display number of counts where i want them to b....infact im not able to display the right value at the right place....here it is...

 

 

<?php

session_register('v1');

session_register('v2');

session_register('v3');

?>

<?php

echo "<html><head><title>webpage counter</title></head><body>";

if(isset($_GET['whpage'])){

echo "<b>You are on page".$_GET['whpage']."<b><br><br>";

$_SESSION["v".$_GET['whpage']]++;

echo "No of visits ".$_SESSION["v".$_GET['whpage']]."<br>"; this line displays count perfectly fine

}

for($i=1;$i<=4;$i++){

if(isset($_GET['whpage'])==$i){

echo "<b><a href=\sesio.php?".session_id()."&whpage=$i\">Page $i</a></b>";

}

else{

echo "<a href=\sesio.php?".session_id()."&whpage=$i\">Page $i</a>";

}

echo ", which you have chosen ".$_SESSION["v".$i]." times.<BR>\n";here the number of counts are not being displayed i want them to be here

echo $_SESSION['v1'];i wrote this line just for testing but it isnt displaying anything

}

//session_destroy();

echo "<br><br>";

echo "</body></html>";

?>

 

 

any help wud really be appreciated

Few problems I see. session_register should not be used, it is depreciated. Remove it completely from your code.

 

The main problem I see is you're not calling [m]session_start[/b]. This must be called at the top of your script whenever you are using sessions.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.