bassguru Posted August 25, 2009 Share Posted August 25, 2009 Hello everyone, I need help reading an array that has been serialized to a .txt file. I have a page that needs to read the array and have the variables and values available so i can use them throughout the page. Here is what I have so far; it is the code I use to write the array to the .txt file: $array = array( "uimg" => "default", "pname" => "guest", "about" => "About me...", ); $str = serialize($array); $userfile = $_POST['username'].'.txt'; $handle = fopen($userfile, 'w+'); fwrite($handle, $array); fclose($handle); What I need now is a way to unserialize the array on the other page so I can identify the variables/values for page customisation. Many thanks in advance bassguru Link to comment https://forums.phpfreaks.com/topic/171757-read-from-serialized-array-on-txt-file/ Share on other sites More sharing options...
trq Posted August 25, 2009 Share Posted August 25, 2009 Seems like allot of manual work to do roughly what sessions already do. Link to comment https://forums.phpfreaks.com/topic/171757-read-from-serialized-array-on-txt-file/#findComment-905671 Share on other sites More sharing options...
bassguru Posted August 25, 2009 Author Share Posted August 25, 2009 It would seem that way. However, the information stored is not short term as it is for a user's personal profile. The variables of the array are the actual settings for the pages (such as profile name, about myself etc...). I've decided not to use a DB to store the values; I have instead set up a system where each account created on the website generates an unique text file that holds the settings for the said users profile settings. Link to comment https://forums.phpfreaks.com/topic/171757-read-from-serialized-array-on-txt-file/#findComment-905678 Share on other sites More sharing options...
trq Posted August 25, 2009 Share Posted August 25, 2009 I have instead set up a system where each account created on the website generates an unique text file that holds the settings for the said users profile settings. Then why not load them into the $_SESSION array when a user logs in and use them from there? Otherwise, your going to need to use some mechanism to determine who is who anyway. Link to comment https://forums.phpfreaks.com/topic/171757-read-from-serialized-array-on-txt-file/#findComment-905679 Share on other sites More sharing options...
bassguru Posted August 25, 2009 Author Share Posted August 25, 2009 Because each profile can be altered by the user (such as changing the text or display pic) and other users can view the profile. Therefore, I don't believe $_SESSION would work for this, unless I'm completely wrong and have missed the point? Link to comment https://forums.phpfreaks.com/topic/171757-read-from-serialized-array-on-txt-file/#findComment-905682 Share on other sites More sharing options...
trq Posted August 25, 2009 Share Posted August 25, 2009 Id say you've missed the point. Generally, profile information is stored within a database (you can use a text file if you wish though). I don't see why this needs to be carried around by a user from request to request though. Link to comment https://forums.phpfreaks.com/topic/171757-read-from-serialized-array-on-txt-file/#findComment-905687 Share on other sites More sharing options...
bassguru Posted August 25, 2009 Author Share Posted August 25, 2009 I think I know what you are on about... You think I should create session variables to use when the user logs on to the website. However, what I want is a text file that is generated when a user CREATES a NEW account; a file that holds values for as long as the account exists. Am I correct or am I completely oblivious? Link to comment https://forums.phpfreaks.com/topic/171757-read-from-serialized-array-on-txt-file/#findComment-905688 Share on other sites More sharing options...
bassguru Posted August 25, 2009 Author Share Posted August 25, 2009 If you think I should store the values in a db then I probably should... this serializing arrays/unserializing is giving me a headache =p thanks for all the help anyway thorpe Link to comment https://forums.phpfreaks.com/topic/171757-read-from-serialized-array-on-txt-file/#findComment-905690 Share on other sites More sharing options...
trq Posted August 25, 2009 Share Posted August 25, 2009 I think I know what you are on about... You think I should create session variables to use when the user logs on to the website. However, what I want is a text file that is generated when a user CREATES a NEW account; a file that holds values for as long as the account exists. Am I correct or am I completely oblivious? If you want to store data permanently (for as long as an account exists) you can use either a database (much preferred) or text files. Doesn't really matter. However to be able to identify which user belongs to which database record (or file) your users need to be logged in (usually done with sessions). Its really two different things you need to do here. Link to comment https://forums.phpfreaks.com/topic/171757-read-from-serialized-array-on-txt-file/#findComment-905693 Share on other sites More sharing options...
bassguru Posted August 25, 2009 Author Share Posted August 25, 2009 I have already set up $_SESSION variables for the username and password (MD5) when the user logs on, just as you mentioned (the encrypted password is checked against the DB password at each page for security). The .txt file array and DB values are the possible solutions for long-term variable storage for the profile settings. DB does seem alot more appealing and will use it. Link to comment https://forums.phpfreaks.com/topic/171757-read-from-serialized-array-on-txt-file/#findComment-905697 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.