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?] Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. ?> Quote Link to comment 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. Quote Link to comment 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']}"; ?> Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.