Jump to content

php sessions


flit

Recommended Posts

Sessions have nothing to do with a database. And, what do you mean by "add lines to the end of a existing session[file]". While the data is stored in a file on the server, the data is created/accessed as an array - you don't have any control over how the data is stored.

Link to comment
https://forums.phpfreaks.com/topic/99981-php-sessions/#findComment-511243
Share on other sites

Ok.

 

I created a file called page1.php with the following code:

<?php

session_start();

?>

 

<?php

$_SESSION['red']='red';

$_SESSION['blue']='blue';

print "Done";

?>

------------------------------------

I created another file called page2.php with the following code:

 

<?php

session_start();

 

echo "Roses are ".$SESSION['red'];

echo "Violets are: ".$SESSION['blue'];

?>

------------------------------------

It creates a session file with:

red|s:3:"red";blue|s:4:"blue";

 

Now I want to add another line at the end of the session file

red|s:3:"red";blue|s:4:"blue";

->new line

 

I hope you can understand my example, BTW sorry for my bad english.

Link to comment
https://forums.phpfreaks.com/topic/99981-php-sessions/#findComment-511266
Share on other sites

There's no need to go fiddling around with the session file. Just use the $_SESSION array

 

<?php
session_start();

echo "Roses are ".$SESSION['red'];
echo "Violets are: ".$SESSION['blue'];
$_SESSION['foo'] = 'bar'; //adds another session variable called foo with the value bar.
?>

Link to comment
https://forums.phpfreaks.com/topic/99981-php-sessions/#findComment-511269
Share on other sites

You could even go one step further and do this,

 

<?php

$_SESSION['colours'] = array("red" => "red", "blue" => "blue", "green" => "green");

echo "Roses are {$_SESSION['colours']['red']}, Violets are {$_SESSION['colours']['blue']}, Grass is {$_SESSION['colours']['green']}";
?>

Link to comment
https://forums.phpfreaks.com/topic/99981-php-sessions/#findComment-511279
Share on other sites

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.