Page 1 of 1

adding a array value with fwrite!

Posted: Fri Nov 28, 2003 9:31 pm
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!

Posted: Fri Nov 28, 2003 10:13 pm
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...

Posted: Fri Nov 28, 2003 10:17 pm
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?

Posted: Fri Nov 28, 2003 10:18 pm
by dull1554
and how would i use one, keep in mind i dont have a database

Posted: Fri Nov 28, 2003 10:29 pm
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