View Full Version : how would one do this? (easy php/perl question)
Gayowulf
November 17th, 2002, 15:02
I'd like to make a simple form that submits whatever someone has entered in the text fields to a dat file
THe thing is that I want it to be entered into the dat file in a cetain format:
Username|Password|0
Would that be a pretty easy thing to do?
Dusty
November 17th, 2002, 15:33
Something like this?
#!perl
read(STDIN,$buffer,$ENV{'CONTENT_LENGTH'});
foreach $pair(split(/&/,$buffer)){
($name,$value)=split(/=/,$pair);
$value=~tr/+/ /;$value=~s/%(..)/pack('c',hex($1))/ge;
$f{$name}=$value;
}
open(FILE,'>>file.dat');
print FILE $f{'username'}.'|'.$f{'password'}.'|'.$f{'number'}."\n";
close(FILE);
print 'Location: /thankyou.html'."\n\n";
This assumes the form is POST and its elements are "username", "password", and "number" (this can easily be edited). After it's added to the file, it redirects the user to thankyou.html.
Gayowulf
November 17th, 2002, 15:43
yeah that looks right.
The number is just a given, though. It's always '0'
how about this in php?
<?
if(isset($_POST['submit'])) {
$fp = fopen("test.dat", "w,a");
$body = $_POST['username']."|".$_POST['password']."|"."0";
fputs($fp, $body);
fclose($fp);
}
?>
Powered by vBulletin® Version 4.1.7 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.