adding a array value with fwrite!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

adding a array value with fwrite!

Post by dull1554 »

heres my problem.....When a user wants to register at my site they fill in a form, the form gets parsed and certain info gets writen to a text file, i also need to add a value to an array that is stored in a seperate file, i don't know how to do this.

heres my code.....

register.php

Code: Select all

<?php

//config
SetCookie("complexscriptingregistration", "cookieswork",time()+60);
$userinfo = "include/userinfo.txt";
$userarray = "include/userarray.php";
$time = date("D d of F, h:i a");
$realname = $_POST['realname'];
$username = $_POST['username'];
$email = $_POST['email'];
$password = ($_POST['pass1']);
$password1 = md5($_POST['pass1']);
$password2 = md5($_POST['pass2']);

//config


if ($password1 != $password2)
   {
       echo "Please retype your passwords, they do not match";
   }
   
else
    {




        if ($_COOKIE['complexscriptingregistration'] == "cookieswork")
        {

        $fp = fopen($userinfo, "a");
        fwrite($fp, "Real name - " .$realname."____");
        fclose($fp);

        $fp = fopen($userinfo, "a");
        fwrite($fp, "User name - " .$username."____");
        fclose($fp);

        $fp = fopen($userinfo, "a");
        fwrite($fp, "E-mail - " .$email."____");
        fclose($fp);

        $fp = fopen($userinfo, "a");
        fwrite($fp, "Registration date - " .$time."____");
        fclose($fp);

        $fp = fopen($userinfo, "a");
        fwrite($fp, "Password - " .$password."| | | | | | | | | | |");
        fclose($fp);
        
        $ua = fopen($userarray, "a");
        $array = //her is where i need code that will let me add the user value to the array($username.$password1)
        fwrite($ua, $array);
        fclose($ua);
        echo "you have cookies enabled!";
        echo "<br>";
        echo "Registration complete!";
        }

        

        else
        {
        echo "you need to enable cookies to be able to register, please enable cookies and try again.";
        }
    }

?>
userarray.php

Code: Select all

<?php $registereduserandpass = array();
      $registereduserandpass[0] = 'blahd914e3ecf6cc481114a3f534a5faf90b';
      $registereduserandpass[1] = 'dull1554d914e3ecf6cc481114a3f534a5faf90b'; ?>
any help would be greatly appreciated!
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

Not my idea of an easy system to work with, I would try to store the data in a database or a comma/tab delimited file and pull the values from the file into usearray.php - not sure if you are up to re-writing the scripts but thats my 2 cents. You can definitely rewrite usearray.php every time with fwrite() but not the best course of action...
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

i wish i had a database, or i wish my server had a database rather, and i know there are better ways to do it but i really don't know how to. whats a comma/tab delimated file?
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

and how would i use one, keep in mind i dont have a database
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

based on what you have so far, you could:
create a shorter version of userinfo.txt with a unique username,encrypted password on each line and use file() to check that each time. You could also create many unique files such as username.txt and place the password on the first line of that... keep working at it, you'll get it right
Post Reply