I have a file with usernames and displaynames store in it like this:
testname=displayname<br>
testname2=displayname2<br>
etc=etc<br>
This list is done twice on the same file, same usernames and same displaynames. I need to replace them in both areas in the lists (needs to be replaced twice)
I am trying to create a form where uses can change their display name. I was trying to copy my code from a page where it looked up passwords for their accounts in a file, found it, and replaced it, however it doesn't seem to be working for this file.
The form for changing their names is simple, it has them enter in their member name (so I could use that to have it find their name in the list) and then uses what they input for a display name to change their display name in the file.
Form Page Code:
<center>Change Display Name:<p>
<form action="http://example.com/xxx/displaynamesave.php" class="form" method="post">
<input "membername" name="membername" /><p><input "displayname" name="displayname" /><p><input name="Submit" type="submit" /></form></p>/center>
and below is my php code for processing
<?
$fileurl = '/xxx/myfiles/sitename/xxx/memberfiletest';
$membername = $_POST['membername'];
$displayname = $_POST['displayname'];
$file = file($fileurl, FILE_IGNORE_NEW_LINES); // Get file as array of lines
foreach ($file AS $n=>$line)
if (substr($line, 0, 20) === '$membername') // Line starts with 'membername'
$file[$n] = '$membername = '.$displayname; // Replace displayname
file_put_contents($fileurl, implode("\n", $file)); // Put file back together
$success_page = 'http://example.com/thisplace/xxx/xxx/successredirector.html';
header('Location: '.$success_page);
?>
When I input the data and hit submit, it goes to my success page, however it doesn't make any changes in the proper file and I'm unsure how to tell what I'm missing.