Jump to content

Add username and values to PHP array


jackr1909

Recommended Posts

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'

);

 

 

?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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?

 

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.