Jump to content

Read from serialized array on .txt file


bassguru

Recommended Posts

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

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.

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.

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?

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.

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.

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.