本文介绍了从CSV加载并转发到不同的URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个CSV文件,我必须读取,根据参数必须转发用户到不同的页面。
例如
I've a CSV file that I must read from and according to the parameters must forward the user to a different page.eg
"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
我很困惑我将如何检查这些参数,即我应该首先检查日期是否为true如果true转发用户。
I am confused as to how I will check these parameters i.e. I should first check whether the date will be true if true forward the user. Any inputs would be appreciated.
我必须检查日期是否有效(无论是否过期),然后检查用户名(KATZ),如果这两个参数为true,我必须将用户转发到www.google.com
I've to basically check for the date if it is valid(whether expired or not) then check the username(KATZ) if these two parameters hold true, I must forward the user to www.google.com
谢谢
推荐答案
这样的事情:
// 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);
这篇关于从CSV加载并转发到不同的URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!