我有一个必须从中读取的CSV文件,根据参数必须将用户转发到其他页面。 例如
"start date","end date","company","url to be forwarded" ---> this line is for explanation only
26/05/2011,26/06/2011 KATZ http://www.google.com
我对如何检查这些参数感到困惑,即如果真实转发用户,我应首先检查日期是否为真。任何投入都将受到赞赏。
我基本上要检查日期是否有效(无论是否过期)然后检查用户名(KATZ)如果这两个参数成立,我必须将用户转发到www.google.com
谢谢
答案 0 :(得分:2)
这样的事情怎么样:
// Username
$username = 'KATZ';
// Open the file.
$fh = fopen('file.csv', 'r')
// Loop through the data.
while ( ($data = fgetcsv($fh)) )
{
$now = time();
// Check that now is later (grater than) than the start date but earlier (less than) than the end date and that the username matches.
if ( $now >= strtotime($data[0]) && $now <= strtotime($data[1]) && $username == $data[2] )
{
// Forward the user
header('Location: ' . $data[3]);
exit;
}
}
// Close the file.
fclose($fh);