lovephp Posted November 5, 2012 Share Posted November 5, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/270308-how-to-addeditdelete-strings-in-php-array-file/ Share on other sites More sharing options...
Muddy_Funster Posted November 5, 2012 Share Posted November 5, 2012 add, eddit, delete what exactly? values, keys or both? Quote Link to comment https://forums.phpfreaks.com/topic/270308-how-to-addeditdelete-strings-in-php-array-file/#findComment-1390300 Share on other sites More sharing options...
lovephp Posted November 5, 2012 Author Share Posted November 5, 2012 add, eddit, delete what exactly? values, keys or both? to b able to add edit the user1 => pass1 Quote Link to comment https://forums.phpfreaks.com/topic/270308-how-to-addeditdelete-strings-in-php-array-file/#findComment-1390305 Share on other sites More sharing options...
Muddy_Funster Posted November 5, 2012 Share Posted November 5, 2012 $userArray['user1'] = 'new password'; ...... $userArray['user4'] = 'pass4'; ...... unset($userArray['user3']); ...... I think that covers it Quote Link to comment https://forums.phpfreaks.com/topic/270308-how-to-addeditdelete-strings-in-php-array-file/#findComment-1390306 Share on other sites More sharing options...
lovephp Posted November 5, 2012 Author Share Posted November 5, 2012 no no, i got these in my users.php files. Ihave to add user and pasword manualy by openin it in a text editor. I am actualy looking for a way to do it with a form. Quote Link to comment https://forums.phpfreaks.com/topic/270308-how-to-addeditdelete-strings-in-php-array-file/#findComment-1390307 Share on other sites More sharing options...
Muddy_Funster Posted November 5, 2012 Share Posted November 5, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/270308-how-to-addeditdelete-strings-in-php-array-file/#findComment-1390310 Share on other sites More sharing options...
lovephp Posted November 5, 2012 Author Share Posted November 5, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270308-how-to-addeditdelete-strings-in-php-array-file/#findComment-1390311 Share on other sites More sharing options...
trq Posted November 5, 2012 Share Posted November 5, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270308-how-to-addeditdelete-strings-in-php-array-file/#findComment-1390313 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.