Jump to content

How To Add/edit/delete Strings In Php Array File?


lovephp

Recommended Posts

guys i got a user.php page where i add users and passwords in array something like

 

'user1' => 'pass1',

'user2' => 'pass2',

'user3' => 'pass3'

 

is there a way i can add edit or delete these with a form than to open it in text file always? Could someone show me how to?

 

I see, so you want to return the username and password information onto a web page from the array and then have a form on that web page that will allow you to alter said information in said array. After which this the web page will also need the ability to write back the changes to the file for them to be made perminant.

 

Is that about right?

yes exactly, i got a non database driven login system. And i curently have to add new users and pasword by opening users.php in text editor. So was looking for a way to do it with a form through which i can add/edit/delete users stored in array in my user.php file.

A better option would be to use a database, but if you must use text files, just edit the array as you normally would, then write it back to the file.

 

eg;

 

users.php

<?php

return array(
'user' => 'whatever',
'user2' => 'whatever2'
);

 

process.php

<?php

$users = include 'users.php';
$users['newuser'] = 'newuserwhatever';
file_put_contents('users.php', '<?php return = ' . var_export($users));

 

The only real caveat as making sure that only one user is writing to the file at a time.

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.