|
1 <?php |
|
2 $conn = mysql_connect('localhost','root','') or die(mysql_error()); |
|
3 mysql_select_db('h4c_db'); |
|
4 |
|
5 // retrieve cookie if it exists |
|
6 if (isset($_COOKIE['h4c_ID'])) |
|
7 { |
|
8 $currID = $_COOKIE['h4c_ID']; |
|
9 } |
|
10 else |
|
11 { |
|
12 // SQL queries |
|
13 $result = mysql_query("INSERT INTO users_tbl (user_ID) VALUES ('')"); |
|
14 $user_id = mysql_query("SELECT MAX(user_ID) as id FROM users_tbl"); |
|
15 |
|
16 $expiry = time() + (3600 * 24 * 30 * 12); |
|
17 |
|
18 //create cookies |
|
19 while ($db_field2 = mysql_fetch_assoc($user_id)) { |
|
20 setcookie('h4c_ID', $db_field2['id'] , $expiry, '/', '', 0); |
|
21 } |
|
22 |
|
23 if (!isset($_COOKIE['h4c_ID'])) |
|
24 { |
|
25 $currID = 1; |
|
26 } |
|
27 } |
|
28 |
|
29 mysql_close(); |
|
30 |
|
31 header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/details.php'); |
|
32 ?> |
|
33 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
34 <html xmlns="http://www.w3.org/1999/xhtml"> |
|
35 <head> |
|
36 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|
37 <title>H4C - checking your user status...</title> |
|
38 </head> |
|
39 |
|
40 <body> |
|
41 <?php |
|
42 // FOR TEST PURPOSES - CHECK COOKIE VALUES |
|
43 /* |
|
44 print '<p><strong>COOKIES------------------------------------------------------------------------</strong></p>'; |
|
45 print 'COOKIE ID = ' . $currID . '<br />'; |
|
46 print 'COOKIE Status = ' . $currStatus . '</p>'; |
|
47 |
|
48 // FOR TEST PURPOSES - READ USERS |
|
49 $result2 = mysql_query('SELECT * FROM users_tbl'); |
|
50 |
|
51 print '<p><strong>LIST OF USERS -----------------------------------------------------------------</strong></p><p>'; |
|
52 |
|
53 while ($db_field = mysql_fetch_assoc($result2)) { |
|
54 print 'USERID: ' . $db_field['user_ID'] . ' | EMAIL: ' . $db_field['user_email'] . ' | USERSTATUS: ' . $db_field['user_status'] . '<br />'; |
|
55 } |
|
56 |
|
57 print '</p>'; |
|
58 */ |
|
59 ?> |
|
60 </body> |
|
61 </html> |