-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommonfunctions.php
50 lines (46 loc) · 1.51 KB
/
commonfunctions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
//Developed by Arslan Khalid
function redirect_to($location) //Redirecct funtion take page name and redirect toward its
{
if (!headers_sent($file, $line))
{
header("Location: " . $location);//setting the location on give page
} else {
printf("<script>location.href='%s';</script>", urlencode($location));//performing URL encoding
# or deal with the problem
}
printf('<a href="%s">Moved</a>', urlencode($location));//moving towards the given location
exit;
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str)
{
$str = @trim($str);//triming the extra character if added through invalid source
if(get_magic_quotes_gpc())
{
$str = stripslashes($str);
}
return mysql_real_escape_string($str); //returing the safe variable back for SQL statement
}
function writelog($userType,$userID,$action)
{
//Getting date from the system
$currentDate= date("d-n-o");
//Sql query for inserting the actioninformation in log file
$logSql="INSERT INTO `logfile`
(`LogID`, `UserType`, `UserID`, `Date`, `Action`)
VALUES ('','$userType','$userID','$currentDate','$action')";
mysql_query($logSql);//executing query
}
// check post values are set
function checkPost($_post, $values)
{
$len = count($values);
for($i = 0; $i < $len; $i++)
{
if(!isset($_post[$values[$i]])) return false;
else if($_post[$values[$i]] == "") return false;
}
return true;
}
?>