1 <?php |
1 <?php |
|
2 function genID($seed, $length) |
|
3 { |
|
4 $ID = ""; |
|
5 srand($seed); |
|
6 for($i = 0; $i < $length; $i++) |
|
7 { |
|
8 $chtype = rand(1, 3); |
|
9 switch($chtype) |
|
10 { |
|
11 case 1: // 0-9 |
|
12 $ID .= chr(rand(48, 57)); |
|
13 break; |
|
14 case 2: // A-Z |
|
15 $ID .= chr(rand(65, 90)); |
|
16 break; |
|
17 case 3: // a-z |
|
18 $ID .= chr(rand(97, 122)); |
|
19 break; |
|
20 } |
|
21 } |
|
22 return $ID; |
|
23 |
|
24 } |
|
25 |
2 // URL validate function |
26 // URL validate function |
3 function validUrl($str) |
27 function validUrl($str) |
4 { |
28 { |
5 return ( preg_match('/^(http|https):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $str)) ? TRUE : FALSE; |
29 return ( preg_match('/^(http|https):\/\/([A-Z0-9][A-Z0-9_-]*(?:\.[A-Z0-9][A-Z0-9_-]*)+):?(\d+)?\/?/i', $str)) ? TRUE : FALSE; |
6 } |
30 } |
36 if ($search_term != "") |
60 if ($search_term != "") |
37 { |
61 { |
38 $conn = mysql_connect('localhost','www-data','www-data') or die(mysql_error()); |
62 $conn = mysql_connect('localhost','www-data','www-data') or die(mysql_error()); |
39 mysql_select_db('members'); |
63 mysql_select_db('members'); |
40 |
64 |
41 $query = mysql_query("INSERT INTO requests_tbl (req_ID, uid, req_val, req_response, req_created) VALUES ('', '$currID', '$search_term', 0, CURDATE())"); |
65 $seed = crc32($search_term); |
42 $query2 = mysql_query("SELECT MAX(req_ID) as id FROM requests_tbl"); |
66 $req_ID = genID($seed + time(), 30); |
|
67 |
|
68 $query = mysql_query("INSERT INTO requests_tbl (req_ID, uid, req_val, req_response, req_created) VALUES ('$req_ID', '$currID', '$search_term', 0, CURDATE())"); |
|
69 # $query2 = mysql_query("SELECT MAX(req_ID) as id FROM requests_tbl"); |
|
70 $query2 = mysql_query("SELECT req_ID as id FROM requests_tbl"); |
43 mysql_close(); |
71 mysql_close(); |
44 |
72 |
45 while ($db_field2 = mysql_fetch_assoc($query2)) |
73 while ($db_field2 = mysql_fetch_assoc($query2)) |
46 { |
74 { |
47 $reqID = $db_field2['id']; |
75 $reqID = $db_field2['id']; |
48 } |
76 } |
49 |
77 |
50 // construct message string |
78 // construct message string |
51 $message = "#" . $currID . "#" . $reqID . "#" . $search_term; |
79 # $message = "#" . $currID . "#" . $reqID . "#" . $search_term; |
|
80 $message = "#" . $reqID . "#" . $search_term; |
|
81 |
52 |
82 |
53 $host="localhost"; |
83 $host="localhost"; |
54 $port = 9090; |
84 $port = 9090; |
55 $timeout = 30; |
85 $timeout = 30; |
56 |
86 |
69 $result .= fgets($sk, 1024); |
99 $result .= fgets($sk, 1024); |
70 } |
100 } |
71 } |
101 } |
72 |
102 |
73 fclose($sk); |
103 fclose($sk); |
74 |
104 header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . 'details.php'); |
75 //header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/details.php?alert=add'); |
105 //header ('Location: http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/details.php?alert=add'); |
76 } |
106 } |
77 ?> |
107 ?> |
78 |
108 |
79 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
109 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |