Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Change username  (Read 13860 times)

0 Members and 1 Guest are viewing this topic.

Blackberry

    Topic Starter


    Adviser
  • For those with wings, fly to your dreams.
    Change username
    « on: March 01, 2006, 02:00:04 AM »
    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 this
    Everybody knows you can't click here. But I know you will try it :)

    Rob Pomeroy



      Prodigy

    • Systems Architect
    • Thanked: 124
      • Me
    • Experience: Expert
    • OS: Other
    Re: Change username
    « Reply #1 on: March 01, 2006, 02:29:29 AM »
    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.
    Only able to visit the forums sporadically, sorry.

    Geek & Dummy - honest news, reviews and howtos

    Blackberry

      Topic Starter


      Adviser
    • For those with wings, fly to your dreams.
      Re: Change username
      « Reply #2 on: March 01, 2006, 02:35:56 AM »
      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 <?php echo'username'?>, will be changed to <?php echo'blackberry'?>
      « Last Edit: March 01, 2006, 02:39:34 AM by blackberry »
      Everybody knows you can't click here. But I know you will try it :)

      egghead

      • Guest
      Re: Change username
      « Reply #3 on: March 01, 2006, 11:19:33 AM »
      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
      « Last Edit: March 18, 2006, 05:37:45 AM by egghead »

      Blackberry

        Topic Starter


        Adviser
      • For those with wings, fly to your dreams.
        Re: Change username
        « Reply #4 on: March 01, 2006, 01:12:26 PM »
        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?
        Everybody knows you can't click here. But I know you will try it :)

        egghead

        • Guest
        Re: Change username
        « Reply #5 on: March 01, 2006, 01:30:46 PM »
        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);
        ?>
        « Last Edit: March 01, 2006, 01:31:08 PM by egghead »

        Blackberry

          Topic Starter


          Adviser
        • For those with wings, fly to your dreams.
          Re: Change username
          « Reply #6 on: March 02, 2006, 12:23:12 AM »
          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-)
          Everybody knows you can't click here. But I know you will try it :)

          egghead

          • Guest
          Re: Change username
          « Reply #7 on: March 02, 2006, 05:02:46 AM »
          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

          Blackberry

            Topic Starter


            Adviser
          • For those with wings, fly to your dreams.
            Re: Change username
            « Reply #8 on: March 02, 2006, 11:23:27 AM »
            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?
            Everybody knows you can't click here. But I know you will try it :)

            egghead

            • Guest
            Re: Change username
            « Reply #9 on: March 02, 2006, 02:16:45 PM »

            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);
            ?>



            Blackberry

              Topic Starter


              Adviser
            • For those with wings, fly to your dreams.
              Re: Change username
              « Reply #10 on: March 02, 2006, 03:17:59 PM »
              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 wrong
              Everybody knows you can't click here. But I know you will try it :)

              Rob Pomeroy



                Prodigy

              • Systems Architect
              • Thanked: 124
                • Me
              • Experience: Expert
              • OS: Other
              Re: Change username
              « Reply #11 on: March 03, 2006, 03:06:51 AM »
              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 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]
              « Last Edit: March 03, 2006, 05:10:58 AM by robpomeroy »
              Only able to visit the forums sporadically, sorry.

              Geek & Dummy - honest news, reviews and howtos

              Blackberry

                Topic Starter


                Adviser
              • For those with wings, fly to your dreams.
                Re: Change username
                « Reply #12 on: March 03, 2006, 04:05:09 AM »
                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....
                Everybody knows you can't click here. But I know you will try it :)

                bigpinkape

                • Guest
                Re: Change username
                « Reply #13 on: March 03, 2006, 05:04:31 AM »
                i am dumb  ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D ;D

                bigpinkape

                • Guest
                Re: Change username
                « Reply #14 on: March 03, 2006, 05:05:09 AM »
                i am a coffee monster as a teacher ;D