forked from ngsankha/codejudge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunctions.php
45 lines (40 loc) · 1.09 KB
/
functions.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
<?php
/*
* Codejudge
* Copyright 2012, Sankha Narayan Guria ([email protected])
* Licensed under MIT License.
*
* Common functions used throughout Codejudge
*/
session_start();
// checks if any user is logged in
function loggedin() {
return isset($_SESSION['username']);
}
// connects to the database
function connectdb() {
include('dbinfo.php');
mysql_connect($host,$user,$password);
mysql_select_db($database) or die('Error connecting to database.');
}
// generates a random alpha numeric sequence. Used to generate salt
function randomAlphaNum($length){
$rangeMin = pow(36, $length-1);
$rangeMax = pow(36, $length)-1;
$base10Rand = mt_rand($rangeMin, $rangeMax);
$newRand = base_convert($base10Rand, 10, 36);
return $newRand;
}
// gets the name of the event
function getName(){
connectdb();
$query="SELECT name FROM prefs";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
return $row['name'];
}
// converts text to an uniform only '\n' newline break
function treat($text) {
$s1 = str_replace("\n\r", "\n", $text);
return str_replace("\r", "", $s1);
}