jackr1909 Posted April 9, 2011 Share Posted April 9, 2011 Hi, i have a password array like below and i was wondering if i could have a script to add values to the bottom of it in the syntax below. Also, could i fit a corresponding email address in there somewhere too. Thanks! <?php //Secure PHP login withou Database by Jerry Low @crankberryblog.com //Find other useful scripts at the Crankberry Blog //Installation Guide At: //http://www.crankberryblog.com/2009/secure-php-login-without-database //Users and Settings $domain_code = 'asdkb767'; //Alpha Numeric and no space $random_num_1 = 83; //Pick a random number between 1 to 500 $random_num_2 = 709; //Pick a random number between 500 to 1000 $random_num_3 = 2; //Pick a random number between 1 to 3 //Usernames can contain alphabets, numbers, hyphens and underscore only //Set users below - Just add '' => '' with the first '' being //the username and the second '' after the => being the password. //Its an array so add an , after every password except for the //last one in the list. As shown below //Eg. $users = array( // 'user1' => 'password', // 'user2' => 'password' // ); $users = array( 'user1' => 'test', 'user2' => 'test' ); ?> Quote Link to comment Share on other sites More sharing options...
dawsba Posted April 9, 2011 Share Posted April 9, 2011 you should read alittle about understanding arrays ie:http://www.howtoforge.com/php_arrays <?php $users=array(); $users['user1']=array('email'=>'bob@bob.com','password'=>'mypass'); $users['user2']=array('email'=>'bob2@bob2.com','password'=>'mypass2'); //so if you get a new user $newusername = 'user3'; $newemail = 'user@bob.com'; $newpassword = 'ilikesprouts'; $users[$newusername]=array('email'=>$newemail,'password'=>$newpassword); ?> Quote Link to comment Share on other sites More sharing options...
jackr1909 Posted April 9, 2011 Author Share Posted April 9, 2011 okay, so how should i add the values to the array from a html form????????? Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted April 9, 2011 Share Posted April 9, 2011 okay, so how should i add the values to the array from a html form????????? need a form: http://www.tizag.com/phpT/forms.php Quote Link to comment Share on other sites More sharing options...
jackr1909 Posted April 9, 2011 Author Share Posted April 9, 2011 yes, i know how to make the html side of the form, but how do i actually add the values to the array file automatically. Thanks, Quote Link to comment Share on other sites More sharing options...
jackr1909 Posted April 9, 2011 Author Share Posted April 9, 2011 by the way, i am using the code that dawsba proposed as opposed to my origonal script. Thanks, Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted April 9, 2011 Share Posted April 9, 2011 yes, i know how to make the html side of the form, but how do i actually add the values to the array file automatically. Thanks, $array is not a file, its a temporary variable on the page stored in a tmp server somewhere, the thing u need to do is: <?php $users=array(); $users['user1']=array('email'=>'bob@bob.com','password'=>'mypass'); $users['user2']=array('email'=>'bob2@bob2.com','password'=>'mypass2'); //so if you get a new user $users['users3'] = array("email" => $_POST['e'], "password" => $_POST['pass']); ?> <form action="" method="post"> Email: <input name="e" type="text" /> Pass: <input name="pass" type="password" /></form> Ted Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 9, 2011 Share Posted April 9, 2011 Have you defined how you are going to store the information in the file? Are you going to write actual php code (the array() statements) to the file so that you can include it to get the array of information? Are you going to write just the information as CSV data so that you need to read and loop over it yourself? Are you going to serialize/unserialize the data so that you can convert it to/from an array in your code? Are you going to store it as XML? Quote Link to comment Share on other sites More sharing options...
jackr1909 Posted April 9, 2011 Author Share Posted April 9, 2011 i am a noob and, faced with that question, didn't know where to start. I just have a code templete like that and(simply) want to be able to generate a form which adds information to that array without me doing that manually! Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted April 9, 2011 Share Posted April 9, 2011 i am a noob and, faced with that question, didn't know where to start. I just have a code templete like that and(simply) want to be able to generate a form which adds information to that array without me doing that manually! This stores variables in a file.txt make sure u have the right permission: <?php //writes into test.txt: $fp = fopen('test.txt', 'a'); fwrite($fp, "{$_POST['user']},{$_POST['pass']},\n"); fclose($fp); //gets info from test.txt: $files = file("test.txt"); foreach ($files as $file) { $data = explode(",", $file); echo "User: {$data[0]} with Password: {$data[1]}<br />";} ?> <form action="" method="post"> User: <input name="user" type="text" /> Pass: <input name="pass" type="password" /> <input type="submit" /> </form> Here is a simple script that puts it to work. Good luck! Ted Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 9, 2011 Share Posted April 9, 2011 Storing sensitive information in a .txt file that is in a public accessible folder allows anyone who guesses or finds the name (many servers have directory listing turned on) of that file to simply request that file to get all the information in it. Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted April 9, 2011 Share Posted April 9, 2011 Storing sensitive information in a .txt file that is in a public accessible folder allows anyone who guesses or finds the name (many servers have directory listing turned on) of that file to simply request that file to get all the information in it. Thats true, the best is mysql, but I think its better if u understand how to write to a text file before u start that. Ted Quote Link to comment Share on other sites More sharing options...
jackr1909 Posted April 9, 2011 Author Share Posted April 9, 2011 It's stored in a pho file, which is server side. The only was they can view the code is if they actually login to my domain hosted or get a hold of an editable version from somewhere. That's where I want to submit the username and password to in the signup process. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 9, 2011 Share Posted April 9, 2011 Your array might be in with your php code now, but to do what you are asking would require that you rewrite that entire php code file every time you add or change the username/password.. information. You will eventually end up messing up your php code file by doing this. Your form processing code that adds/changes the information need to access the values and any page the needs to authenticate a visitor needs to access the values. You need to store the usernames/passwords... in a separate file and then include/read that information into your php scripts that needs access to that information. Quote Link to comment Share on other sites More sharing options...
jackr1909 Posted April 9, 2011 Author Share Posted April 9, 2011 Could I have a script.please and a script for adding the username, password, email, etc. Thanks Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 9, 2011 Share Posted April 9, 2011 Programming help forums are not about writing scripts for you (see the freelancing forum section if you want to pay to have someone do this for you.) Programming help forums are about people attempting to write their own code and are asking for help with a specific problem or a specific error with their code. Quote Link to comment Share on other sites More sharing options...
jackr1909 Posted April 9, 2011 Author Share Posted April 9, 2011 thats what i am doing, if you looked at the top of the thread you would see a 25 line block of code written. I am just asking for help with one aspect of this (adding values automatically), just because the conversation went towards new scripts dosen't mean i don't have the origonal intention of fixing one little problem in the code. Quote Link to comment Share on other sites More sharing options...
akeane Posted April 9, 2011 Share Posted April 9, 2011 Use the idea of writing .txt file but use extension .php. Then use the .php file in an include... you will pick up any changes to the .php file. Quote Link to comment Share on other sites More sharing options...
ted_chou12 Posted April 10, 2011 Share Posted April 10, 2011 thats what i am doing, if you looked at the top of the thread you would see a 25 line block of code written. I am just asking for help with one aspect of this (adding values automatically), just because the conversation went towards new scripts dosen't mean i don't have the origonal intention of fixing one little problem in the code. technically, since you are storing your information in a PHP file (please spell it correctly next time, I didnt catch what pho was until now). what you have GIVEN on the first post is ONLY INFORMATION not CODE. So PFMaBiSmAd is right, we shouldn't be writing code for you, especially ones that doesn't make sense, why would you try to store information in a formatted PHP file anyways, its just stupid? messing up the coding would just show it all out or result in PHP syntax. Now, consider about storing it in mysql or txt files? (text files can be locked in a dir that has .htaccess files which disable direct access from web browser, so it's secured in a sense.) Ted Quote Link to comment Share on other sites More sharing options...
jackr1909 Posted April 10, 2011 Author Share Posted April 10, 2011 dont worry, i found out what was wrong with my DB login (just for your curiosity it was i put the username and DB as DBUSERNAME instead of CPANELUSERNAME_DBUSERNAME and the same thing for the DB Name. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.