Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.