The file is a basic txt file located in paths/file.txt. It contains many lines though and I need a code that will:
1) loop the number of lines the text file is
2) retrieve the values(1-4) of the first line in which user input is equal to value4 of that line
3) i want to redirect the user to a page, depending on the values, based on an 'if' condition
The code on the page has a text box and asks for email address. It then will check the address of each line until it finds a matching one. Then, depending on all four values of the first matching line, the user will be redirected to a specified page, for example: 'their name.htm'. If the emails don't match, it will go to '/newemail.htm'
I think it is possible, but I am not quite sure where to start!
Last edited by steelersfan88; 01-29-2004 at 03:36 PM.
<?php
$fileName = "paths/file.txt"; // path and name of file
$newMailPage = "newmail.htm"; // path and name of new email page
$email = $_GET['email']; // form email input; change 'email' to the name of the input; change to $_POST['email'] if you use the POST method
$fileHandle = file($fileName); // open the file and read assign each line to an array
foreach ($fileHandle as $line) {
list($val1, $val2, $val3, $val4) = explode(',', $line); // split the line into the four variables
$val1 = trim($val1); // remove whitespace from the front and back of the string
$val2 = trim($val2);
$val3 = trim($val3);
$val4 = trim($val4);
if ($val4 == $email) {
header("Location: " . $val1 . ".htm"); // send a redirect header
exit; // exit the program, so the user won't be redirected to the new mail page
}
}
header("Location: " . $newMailPage);
?>
Bookmarks