1.

Solve : Change username?

Answer»

As you have followed a few posts of me you would see that I'm writing a login-script. First of all I would thank robpomeroy for all the help I had from him. (secuirity for the script, and help with pictures in the script!). Now I have a new question. I would like that my users can change there name (not  login name, just there name).

On all the pages there name is DISPLAYED by this code:
Code: [Select]include("username.txt");?>

and in the txt file this is written:
Code: [Select]<?php echo'username'?>

Now I would like to have that it is possible to change this name. So I would like to have a textform where you can type your name and a submit button and than your name is changed (in the text file). Does anyone knows how to do thisIs there a chance you can keep your users' details in a database (e.g. MySQL)?  Your answer will make a big difference to my suggested solution. Quote

Is there a chance you can keep your users' details in a database (e.g. MySQL)?  Your answer will make a big difference to my suggested solution.

No I don't have mysql on my server, not even msql. But the thing I actually want is: that the name you typed in the box, wil be changed in the textfile. Example if you type Blackberry and then submit, that the textfile , will be changed to something like...

Code: [Select]<?
rename("/dir/username.txt", "/dir/newNAME.txt");
$read = file_get_contents(username.txt);
$replace = str_replace("username", "newName", "$read");
$fp = fopen("username.txt", "W");
fputs($fp, $replace);
fclose($fp);
?>

if you dont understand a command ther explained on php.net or i'll be happy to fit it in your code if you posted it?

http://something like...

[code]
<?
rename("/dir/username.txt", "/dir/newNAME.txt");
$read = file_get_contents(username.txt);
$replace = str_replace("username", "newName", "$read");
$fp = fopen("username.txt", "w");
fputs($fp, $replace);
fclose($fp);
?>
[/code]

if you dont understand a command ther explained on php.net or i'll be happy to fit it in your code if you posted it?

[url]http://127.0.0.1/index.php
Quote
something like...

Code: [Select]<?
rename("/dir/username.txt", "/dir/newNAME.txt");
$read = file_get_contents(username.txt);
$replace = str_replace("username", "newName", "$read");
$fp = fopen("username.txt", "w");
fputs($fp, $replace);
fclose($fp);
?>

thanx for the code... But it isn't exactly what I want to. I want that DE username.txt file stays with the same name, only the text within it should change. This is my submit form

<body>

<form name="post" method="post" action="config.php">

<head>

<title></title>

</head>


&nbsp;

<p>&nbsp;</p>

<p><font face="Arial" color="#000080">Type your new name </font></p>

<p><font face="Arial" size="2"> <input type="text" name="name" value="" maxlength="90" size= 22 tabindex="1">


<input type="submit" name="Submit" value="Toevoegen" tabindex="1">

</font>

</form>

</body>

if you dont understand a command ther explained on php.net or i'll be happy to fit it in your code if you posted it?
then simply take away the part that changes the text file,
config.php
Code: [Select]<?

$nename = $_POST['name']
$read = file_get_contents(username.txt);
$replace = str_replace("username", "$nename", "$read");
$fp = fopen("username.txt", "w");
fputs($fp, $replace);
fclose($fp);
?>
Thank you for the scrip, but when I install it, it doesn't work....  . I don't know why but the file config.php gives just a white screen. Btw I think your script only change the word USERNAME if it is in the textfile. But what if I want to change my name again after username: example to blackberry, how do I change that then....


greetz


blackberry  8-)It only changes the word username to a new word, and it appers blank because it dosent desply any html. Presumabley you already no the name in the textfile if ther logged in?
if not i have some code i created and you can use it to find out the username in the file.
At the MOMENT i'm at collage i'll post it when i get home Quote
It only changes the word username to a new word, and it appers blank because it dosent desply any html. Presumabley you already no the name in the textfile if ther logged in?
if not i have some code i created and you can use it to find out the username in the file.
At the moment i'm at collage i'll post it when i get home

about your html your right, sorry about that one.... But it stays with one problem, it can't change to the name, it just become username, how many thimes I type an other name in the TEXTBOX... Do you know what the problem is?
Itstead of the text file containg echo (name) just put the name in it.
eg "Fred"

once done that just get the context of that file and echo it.
Code: [Select]<?
$read = file_get_contents(username.txt);
echo ("$read");
?>
config.php
Code: [Select]<?

$newname = $_POST['name']
$read = file_get_contents(username.txt);
$replace = str_replace("$read", "$nename", "$read");
$fp = fopen("username.txt", "w");
fputs($fp, $replace);
fclose($fp);
?>


I don't know what I do wrong but it still doesn't work... Now the reading file that shows the name don't work anymore. Can you give me some advice about what I may be doing wrongI don't think this will work the way you want it to, blackberry.  The contents of the username.txt file will be served up to all visitors to your web site.  So if one person changes it, every other person seeing the next page will be faced with the wrong username.

How about instead using a cookie stored on the user's PC?  No need to change any file on your server then.  Their usernames get stored as a cookie on their PC - you can check for the presence of it and respond accordingly.

What do you think?

Incidentally, when you were seeing a white page aboe, that may also have been because there was an error in the php - a missing semicolon at the end of the first line.  If display_errors is set to off in php.ini, then you will not get a report - just a blank page.

[edit]Changed DisplayErrors to the correct name, display_errors[/edit] Quote
I don't think this will work the way you want it to, blackberry.  The contents of the username.txt file will be served up to all visitors to your web site.  So if one person changes it, every other person seeing the next page will be faced with the wrong username.

How about instead using a cookie stored on the user's PC?  No need to change any file on your server then.  Their usernames get stored as a cookie on their PC - you can check for the presence of it and respond accordingly.

What do you think?

Incidentally, when you were seeing a white page aboe, that may also have been because there was an error in the php - a missing semicolon at the end of the first line.  If DisplayErrors is set to off in php.ini, then you will not get a report - just a blank page.

a
I unsderstand, but it is just a login for one person. SO changing the name in a text file will work, if I have the right code....i am dumb   i am a coffee monster as a teacher


Discussion

No Comment Found