NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Write FORM data to text file?

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Reply
 
LinkBack Thread Tools
Old 06-27-2009, 04:33 PM THREAD STARTER               #1 (permalink)
DomainersUniversity.com
 
Gene's Avatar
Join Date: Feb 2005
Location: Oswego, NY
Posts: 4,735
Gene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond repute
 


Member of the Month
April 2005
Ethan Allen Fund Cancer Survivorship Baby Health Cystic Fibrosis Marrow Donor Program Parkinson's Disease Child Abuse Save a Life Animal Rescue Save a Life Save a Life Animal Rescue

Write FORM data to text file?


I'd like to create a form with 3 fields, which will
take the contents of each of the 3 fields and store
them in a text file.

==============================================
Form
==============================================

Enter Website URL Here: [_________________]
????: NamePros.com http://www.namepros.com/programming/592866-write-form-data-to-text-file.html
Enter Account ID# Here: [_________________]
Enter Email Address Here: [_________________]

[ SUBMIT ]

==============================================



When the user submits that form, the information
gets written to a text file containing only this:

==============================================
Text file named info.inc
==============================================

<?php
$weburl = "WebSiteName.com";
$accountid = "12345";
$email = "usersemail@anymailaddress.com";
?>

==============================================


Any time the user goes back to the form above
and changes the data in any of the 3 fields,
the text file will be overwritten accordingly.

Note: The text file will have the CHMOD
permission set to 644 so nobody else can
write to it.

Note: The form will be in a password protected
folder.

No help needed to create the form and
password protected folder. I just need to
know how to get the form SUBMIT to overwrite
the text file to contain the new form data.

Thanks!

Gene
__________________
.
.

Expired Domain Search -- ExpiredDomainBoss.com | Sell Domain Names -- DomainProfitsClub.com
-----------------------------------------------------------------------------------------------
Gene is offline   Reply With Quote
Old 06-27-2009, 09:09 PM   #2 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Just curious, why not use a MySQL database? Would be easier to work with and IMHO more secure
Eric is offline   Reply With Quote
Old 06-27-2009, 09:45 PM   #3 (permalink)
Senior Member
 
nasaboy007's Avatar
Join Date: Jul 2005
Location: NJ
Posts: 1,219
nasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud of
 



is it only supposed to hold those 3 pieces of info at one time? (as in different text files for different users).


if so, this should work. (untested, written on-the-fly):

PHP Code:
<?php
$weburl 
$_POST['weburl'];
$accountid $_POST['accountid'];
$email $_POST['email'];

//This should be the path to the text file, relative to the PHP file this is saved as.
$file "info.inc";

$fh fopen($file'w');

$string "<?php \n \$weburl = \"" $weburl "\";\n\$accountid = \"" $accountid "\";\n\$email = \"" $email "\";\n ?>";

fwrite($fh$string);

fclose($fh);

?>

????: NamePros.com http://www.namepros.com/showthread.php?t=592866
????: NamePros.com http://www.namepros.com/showthread.php?t=592866
That should be the action of the form, the inputs should be named "weburl", "accountid", and "email". This is the example text file populated:

Quote:
<?php
$weburl = "WebSiteName.com";
$accountid = "12345";
$email = "usersemail@anymailaddress.com";
?>

Do you need to be worrying about sanitizing your data (incase it will be used for other scripts), because that is VERY open to injections?
nasaboy007 is offline   Reply With Quote
Old 06-28-2009, 05:45 AM THREAD STARTER               #4 (permalink)
DomainersUniversity.com
 
Gene's Avatar
Join Date: Feb 2005
Location: Oswego, NY
Posts: 4,735
Gene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond repute
 


Member of the Month
April 2005
Ethan Allen Fund Cancer Survivorship Baby Health Cystic Fibrosis Marrow Donor Program Parkinson's Disease Child Abuse Save a Life Animal Rescue Save a Life Save a Life Animal Rescue
Originally Posted by Eric View Post
Just curious, why not use a MySQL database? Would be easier to work with and IMHO more secure
Mainly because this is for a project where I provide turn-key websites, and this set of files would be bundled along with it so each user can customize their own site with these bits of information. I don't want to make each user have to create a database.

---------- Post added at 07:45 AM ---------- Previous post was at 07:43 AM ----------

Originally Posted by nasaboy007 View Post
is it only supposed to hold those 3 pieces of info at one time? (as in different text files for different users).


if so, this should work. (untested, written on-the-fly):

PHP Code:
<?php
$weburl 
$_POST['weburl'];
$accountid $_POST['accountid'];
????: NamePros.com http://www.namepros.com/showthread.php?t=592866
$email $_POST['email'];

//This should be the path to the text file, relative to the PHP file this is saved as.
$file "info.inc";

$fh fopen($file'w');

$string "<?php \n \$weburl = \"" $weburl "\";\n\$accountid = \"" $accountid "\";\n\$email = \"" $email "\";\n ?>";
????: NamePros.com http://www.namepros.com/showthread.php?t=592866

fwrite($fh$string);

fclose($fh);

?>

That should be the action of the form, the inputs should be named "weburl", "accountid", and "email". This is the example text file populated:




Do you need to be worrying about sanitizing your data (incase it will be used for other scripts), because that is VERY open to injections?
Thank you for that! I'll work with it and see if it works. Can you please explain what you mean by "sanitizing" the data, and what do you mean by it being "VERY open to injections"? Thanks!
__________________
.
.

Expired Domain Search -- ExpiredDomainBoss.com | Sell Domain Names -- DomainProfitsClub.com
-----------------------------------------------------------------------------------------------
Gene is offline   Reply With Quote
Old 06-28-2009, 05:57 AM   #5 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Originally Posted by Gene View Post
Mainly because this is for a project where I provide turn-key websites, and this set of files would be bundled along with it so each user can customize their own site with these bits of information. I don't want to make each user have to create a database.
Ahh, I see
Originally Posted by Gene View Post


---------- Post added at 07:45 AM ---------- Previous post was at 07:43 AM ----------



Thank you for that! I'll work with it and see if it works. Can you please explain what you mean by "sanitizing" the data, and what do you mean by it being "VERY open to injections"? Thanks!
Well, taking info. from a user and putting it directly into PHP code like that can be dangerous. There's several ways it can be manipulated. Also you have to be careful about quotes in what they enter - adding " in the input could cause the PHP code to error out when it runs. If you're using PHP 5:

(for the $accountid, I'm assuming this is a number?)
PHP Code:
<?php
????: NamePros.com http://www.namepros.com/showthread.php?t=592866

$weburl 
trim($_POST['weburl']);
????: NamePros.com http://www.namepros.com/showthread.php?t=592866
$accountid trim($_POST['accountid']);
$email trim($_POST['email']);

if (!
filter_var($weburlFILTER_VALIDATE_URL))
{
    echo 
'Please enter a valid URL';
    exit;
}

if (!
filter_var($accountidFILTER_VALIDATE_INT))
{
    echo 
'Please enter a valid account id';
    exit;
}

if (!
filter_var($emailFILTER_VALIDATE_EMAIL))
{
    echo 
'Please enter a valid email address';
    exit;
}

//This should be the path to the text file, relative to the PHP file this is saved as.
$file "info.inc";

// PHP 5 has file_put_contents
$string "<?php\n\n\$weburl = \"" $weburl "\";\n\$accountid = " $accountid ";\n\$email = \"" $email "\";\n\n?>";
file_put_contents($file$string);

/**
$fh = fopen($file, 'w');
fwrite($fh, $string);
fclose($fh);
*/

?>
Eric is offline   Reply With Quote
Old 06-28-2009, 06:28 AM   #6 (permalink)
Senior Member
 
nasaboy007's Avatar
Join Date: Jul 2005
Location: NJ
Posts: 1,219
nasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud of
 



sanitizing your input means that, for example, if the user were to put something like

Quote:
"; echo $password;
(very crude) into one of the text fields, your text file could look like this:
????: NamePros.com http://www.namepros.com/showthread.php?t=592866

Quote:
<?php
$weburl = "";
echo $password;
$accountid = "12345";
$email = "usersemail@anymailaddress.com";
?>
And so when you put this into another script (for the variables), PHP will think that you actually wanted to display the variable "$password", and so it will show it.
nasaboy007 is offline   Reply With Quote
Old 06-28-2009, 06:33 AM THREAD STARTER               #7 (permalink)
DomainersUniversity.com
 
Gene's Avatar
Join Date: Feb 2005
Location: Oswego, NY
Posts: 4,735
Gene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond repute
 


Member of the Month
April 2005
Ethan Allen Fund Cancer Survivorship Baby Health Cystic Fibrosis Marrow Donor Program Parkinson's Disease Child Abuse Save a Life Animal Rescue Save a Life Save a Life Animal Rescue
I see. Thank you both for your valuable input. Do you have any suggestions on how to accomplish this in a better, more secure way (without using MySQL)?
__________________
.
.

Expired Domain Search -- ExpiredDomainBoss.com | Sell Domain Names -- DomainProfitsClub.com
-----------------------------------------------------------------------------------------------
Gene is offline   Reply With Quote
Old 06-28-2009, 02:14 PM   #8 (permalink)
Senior Member
 
nasaboy007's Avatar
Join Date: Jul 2005
Location: NJ
Posts: 1,219
nasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud of
 



honestly, (if the way i understand it is correct), it may not matter that much. if you are selling a website to a client, then sending that client to a portal page where they will input the information that they want (login/info/accountid), i assume that your clients can be trusted (to the point where COMPLETE sanitization shouldn't be necessary) and that will never be edited/populated again (once it is initially set).

i suggest just making sure that magic quotes are enabled in PHP (put <?php phpinfo(); ?> in a php file and go to it on your server, it'll show the config of your server. look for the enable_magic_quotes (or something w/ magic quotes in it) and make sure it's enabled).
nasaboy007 is offline   Reply With Quote
Old 06-28-2009, 02:45 PM THREAD STARTER               #9 (permalink)
DomainersUniversity.com
 
Gene's Avatar
Join Date: Feb 2005
Location: Oswego, NY
Posts: 4,735
Gene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond repute
 


Member of the Month
April 2005
Ethan Allen Fund Cancer Survivorship Baby Health Cystic Fibrosis Marrow Donor Program Parkinson's Disease Child Abuse Save a Life Animal Rescue Save a Life Save a Life Animal Rescue
Originally Posted by nasaboy007 View Post
honestly, (if the way i understand it is correct), it may not matter that much. if you are selling a website to a client, then sending that client to a portal page where they will input the information that they want (login/info/accountid), i assume that your clients can be trusted (to the point where COMPLETE sanitization shouldn't be necessary) and that will never be edited/populated again (once it is initially set).

i suggest just making sure that magic quotes are enabled in PHP (put <?php phpinfo(); ?> in a php file and go to it on your server, it'll show the config of your server. look for the enable_magic_quotes (or something w/ magic quotes in it) and make sure it's enabled).
Thanks for that information. The clients upload all the files to their own hosting account, and they are the only one(s) using the form (which is password protected) to set up the site or to modify it in the future. So, the magic quotes thing may or may not exist on their hosting account.
__________________
.
.

Expired Domain Search -- ExpiredDomainBoss.com | Sell Domain Names -- DomainProfitsClub.com
-----------------------------------------------------------------------------------------------
Gene is offline   Reply With Quote
Old 06-29-2009, 01:36 PM   #10 (permalink)
Senior Member
 
nasaboy007's Avatar
Join Date: Jul 2005
Location: NJ
Posts: 1,219
nasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud ofnasaboy007 has much to be proud of
 



The way Eric edited it makes it more secure (since you're validating the input). You shouldn't need to worry about sanitizing the data as much, now.

Also, thanks for showing me filter_var, Eric. I had no idea that existed and I've always HATED having to use regexp to validate things. Rep+
nasaboy007 is offline   Reply With Quote
Old 06-29-2009, 03:11 PM   #11 (permalink)
Senior Member
 
Eric's Avatar
Join Date: Mar 2005
Posts: 4,948
Eric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatnessEric Has achieved greatness
 

Member of the Month
MOTM September 2005
Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Animal Rescue Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Baby Health Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse Diabetes Protect Our Planet Multiple Sclerosis Autism Adoption Special Olympics
Originally Posted by nasaboy007 View Post
The way Eric edited it makes it more secure (since you're validating the input). You shouldn't need to worry about sanitizing the data as much, now.

Also, thanks for showing me filter_var, Eric. I had no idea that existed and I've always HATED having to use regexp to validate things. Rep+
Thanks for the rep. and no problem PHP 5 has some awesome features
Eric is offline   Reply With Quote
Old 06-29-2009, 03:22 PM THREAD STARTER               #12 (permalink)
DomainersUniversity.com
 
Gene's Avatar
Join Date: Feb 2005
Location: Oswego, NY
Posts: 4,735
Gene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond reputeGene has a reputation beyond repute
 


Member of the Month
April 2005
Ethan Allen Fund Cancer Survivorship Baby Health Cystic Fibrosis Marrow Donor Program Parkinson's Disease Child Abuse Save a Life Animal Rescue Save a Life Save a Life Animal Rescue
Thanks again to both of you. I guess I've repped you both too much in the past so can't do it again yet, but I sincerely appreciate your help.
__________________
.
.

Expired Domain Search -- ExpiredDomainBoss.com | Sell Domain Names -- DomainProfitsClub.com
-----------------------------------------------------------------------------------------------
Gene is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
Portfolio 4 Sale/Trade Category-Killers, Adult, Traffic, Aged, LLL, LLLLL, Dictionary Archangel Domains For Sale - Make Offer 1 05-20-2009 05:18 PM
I'll pay $25 to code up a contact form with a php file helloypi Web Development Wanted 7 01-05-2008 01:31 AM
Need help in reading from a text file in VB mattonline Programming 3 07-02-2007 08:33 AM
Text file retrieval Alpha Programming 2 08-15-2003 01:23 AM

Liquid Web Smart Servers  
All times are GMT -7. The time now is 05:03 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger