flit Posted April 7, 2008 Share Posted April 7, 2008 Hi there, I am a complete php newbie and I am trying to add lines to the end of a existing session[file] with no success. Can anyone help me add lines to an existing php session[without using a mysql database?] Link to comment https://forums.phpfreaks.com/topic/99981-php-sessions/ Share on other sites More sharing options...
Cep Posted April 7, 2008 Share Posted April 7, 2008 I do not understand your question, what do you mean by add lines to a session? Link to comment https://forums.phpfreaks.com/topic/99981-php-sessions/#findComment-511242 Share on other sites More sharing options...
Psycho Posted April 7, 2008 Share Posted April 7, 2008 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 More sharing options...
flit Posted April 7, 2008 Author Share Posted April 7, 2008 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 More sharing options...
GingerRobot Posted April 7, 2008 Share Posted April 7, 2008 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 More sharing options...
flit Posted April 7, 2008 Author Share Posted April 7, 2008 Thanks for the solution, I am gonna give it a try. Link to comment https://forums.phpfreaks.com/topic/99981-php-sessions/#findComment-511276 Share on other sites More sharing options...
Cep Posted April 7, 2008 Share Posted April 7, 2008 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 More sharing options...
flit Posted April 7, 2008 Author Share Posted April 7, 2008 Thanks Cep, I will try that too. Link to comment https://forums.phpfreaks.com/topic/99981-php-sessions/#findComment-511284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.