Jump to content

vinner

New Members
  • Posts

    2
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

vinner's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thank you forum members for your help after trial and error method I was able to come up with a working code <?php error_reporting(E_ALL|E_STRICT); ini_set("display_errors", "On"); $name_value=$_GET['query']; $fh = fopen('db.csv', 'r'); $now = date("d.m.Y"); $line = 1; if (($handle = fopen("db.csv", "r")) !== FALSE) { while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $num = count($data); $line++; for ($c=0; $c < $num; $c++) { if($name_value == $data[0] AND $data[1] >= $now) { header("Location: $data[2]"); exit(); } else { header("Location: http://localhost/x/client_unauthorized.html"); } } } fclose($handle); } ?> and I feel very happy for doing this on my own
  2. Hello forum members, I am a beginner at programming and at PHP too. My objective is to read a CSV file check the initial two conditions for a match and then forward the user to a link Here is my CSV file php,26.06.2011,http://www.google.com java,26.06.2011,http://www.google.com This is the code that I've written. My problem is that the code does not read the entire contents of the CSV file. It reads the second line but not the first line. I'm a bit confused could someone help me <?php error_reporting(E_ALL|E_STRICT); ini_set("display_errors", "On"); $name_value=$_GET['query']; $fh = fopen('db.csv', 'r'); $now = date("d.m.Y"); $data=fgetcsv($fh); $name=$data[0]; $date=$data[1]; $url=$data[2]; while(list($name, $date, $url) = fgetcsv($fh)) { { if($name_value == $name AND $date>=$now) { header("Location: $url"); exit(); } else { echo "name is $name \t\t name 2 is $name_value<br>"; echo "date is $date \t\t now date is $now<br>"; echo "URL is $url"; } exit; } } ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.