Help with function code
Posted: Sat Apr 26, 2008 5:48 pm
I would like to have a function that takes the customers email address from a certain field, check to make sure the email does not already exist, and if it does not then store the email into a file.
But I am still new to php and I am not sure if what I have so far is correct or even what else needs to be added.
Also where in the script should I place this code?
That is all I have been able to come up with so far.
But I am still new to php and I am not sure if what I have so far is correct or even what else needs to be added.
Also where in the script should I place this code?
Code: Select all
<?php
// Define filename and open in read-write append mode
$filename = 'C:/private/customeremail.txt';
$file = fopen($filename, 'a+');
// If filesize is zero, no names yet registered
// So just write the customer email to file
if (filesize($filename) === 0) {
fwrite($file, "$email");
}
// If filesize is greater than zero, check customer email first
else {
// Move the internal pointer to the beginning of file
rewind($file);
// Loop through file one line at a time while (!feof($file)) {
$line = fgets($file);
// Split line at comma, and check first element against customer email
$tmp = explode(', ', $line);
// close the file
fclose($file);
}
}