Location: PHPKode > projects > VoxRank > voxrankfree/functions.php
<?php
error_reporting(E_ALL);
#######################################################################################
## MySQL is the host location, your host will have to supply this infomation                                                                     ##
$mysql_host = 'localhost';
## MySQL username, this is also supplyed by your host,                                                                                           ##
$mysql_user = 'root';
## MySQL password also supplyed by your host.                                                                                                     ##
$mysql_pass = '';
## MySQL Database name is supplyed by your host                                                                                                   ##
$mysql_base = 'voxrank';
## This is the password used to get access to admin functions for the top site list                       ##
$admin_pass = 'demo';
## This is the password used to get access to admin functions for the top site list                                                           ##
$salt_key = '5nH4lzMy7ugeSMG6rjFas7s60lE4heh4jf';
#######################################################################################


## This revises the admin password / Do not touch! ##
$admin_pass = md5($salt_key.$admin_pass);
##

function db_connect() { // The function will connect and select the the database.
global $mysql_host, $mysql_user, $mysql_pass, $mysql_base;
if (!@mysql_connect($mysql_host, $mysql_user, $mysql_pass)) die("<html>\n<head>\n<title>VoxRank Database Error!</title>\n</head>\n<body>\n<font color=\"#FF0000\" size=\"6\" face=\"Verdana, Arial, Helvetica, sans-serif\">Error!</font><br>\n<font color=\"#000000\" size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">There has been an error connecting to the database, please try back later.<br>\nTo the administrator: There has been a problem with the database username, password, or connection server.</font>\n</body>\n</html>");
if (!@mysql_select_db($mysql_base)) die("<html>\n<head>\n<title>VoxRank Database Error!</title>\n</head>\n<body>\n<font color=\"#FF0000\" size=\"6\" face=\"Verdana, Arial, Helvetica, sans-serif\">Error!</font><br>\n<font color=\"#000000\" size=\"2\" face=\"Verdana, Arial, Helvetica, sans-serif\">There has been an error connecting to the database, please try back later.<br>To the administrator, there has been a problem with the database name, please be sure you have selected the right database.</font>\n</body>\n</html>");
}

function error_msg($title, $text, $die, $start) {
global $errorcolor, $goto, $body_link, $body_alink, $body_vlink, $body_text, $body_bgcolor, $font_face, $font_size, $title_size, $starttime, $vn, $site_title, $small_font_size;
if ($start == 'Y') {
require 'include/header.php';
}
if ($goto == 'Y') echo '<meta http-equiv="refresh" content="3; URL=index.php;">';
echo "<center><b><font size=\"".$title_size."\" face=\"".$font_face."\" color=\"".$errorcolor."\">Error : $title</font></b></center>\n";
echo "<center><font face=\"".$font_face."\" size=\"".$font_size."\">$text</font></center><br>\n";
if ($die == 'Y') {
require 'include/footer.php';
die;
}
}

function table_exists($table) {
	if( mysql_num_rows( mysql_query("SHOW TABLES LIKE '".$table."'"))) {
		return TRUE;
	} else {
		return FALSE;	
	}
}

function id_exists($id) {
$query = @mysql_query('select id from voxrank where id=\''.$id.'\';');
$row = @mysql_fetch_array($query);
	if ($id = $row['id']) {
		return TRUE;
	} else {
		return FALSE;
	}
}

function check_url($url) {
	//open the URL in read mode
	$value=@fopen($url,"r");
	if ($value) $exists=1;
	else $exists=0;
	return $exists;
	fclose($value);
}

    //**************************************
    //     
    // Name: MEL :: Better Check Email Funct
    //     ion
    // Description:**UPDATED** This function
    //     will double check and validate an E-mail
    //     address by checking the sintaxis first a
    //     nd the domain's MX, A and CNAME records 
    //     to be valid and active. It will return T
    //     RUE if the email is valid or FALSE if no
    //     t, very simple. The best approach I've m
    //     ade to validate an Email. Let me know th
    //     is has been useful, your comments and su
    //     ggestions are very much appreciate it. *
    //     *Please Vote**
    // By: Melvin D. Nava
    //
    // Assumes:Relies on the checkdnsrr PHP 
    //     Function to do the DNS work. Not availab
    //     le for Windows. I've included a replacem
    //     ent (ONLY WIN32)
    //
    //This code is copyrighted and has    // limited warranties.Please see http://
    //     www.Planet-Source-Code.com/vb/scripts/Sh
    //     owCode.asp?txtCodeId=1316&lngWId=8    //for details.    //**************************************
    //     
    
    //
    // CHECK EMAIL FUNCTION
    //***********************
    function check_email_mx($email) { 
    	if( (preg_match('/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/', $email)) || 
    		(preg_match('/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/',$email)) ) { 
    		$host = explode('@', $email);
    		if(checkdnsrr($host[1].'.', 'MX') ) return true;
    		if(checkdnsrr($host[1].'.', 'A') ) return true;
    		if(checkdnsrr($host[1].'.', 'CNAME') ) return true;
    	}
    	return false;
    }
    //
    // FIX FOR WINDOWS
    // PROGRAMMERS
    //***********************
    // checkdnsrr is not available
    // under windows I so included
    // the next replacement. You
    // may remove this if you are 
    // gonna publish later over 
    // any Linux/Unix OS
    //
    // thanx Jon Kriek for next snippet
    // and Rickard Sjöquist for notice
    // Melvin D. Nava.
    //
    if (!function_exists('checkdnsrr')) {
    	function checkdnsrr($host, $type = '') {
    		if(!empty($host)) {
    			if($type == '') $type = "MX";
    			@exec("nslookup -type=$type $host", $output);
    			while(list($k, $line) = each($output)) {
    				if(eregi("^$host", $line)) {
    					return true;
    				}
    			}
    			return false;
    		}
    	}
    }


function check_user_info() { // This function is used to check the information about the user
global $username, $password, $password2, $email, $contact, $_REQUEST;
if ($_REQUEST['username'] == '' | $_REQUEST['username'] == ' ' | empty($_REQUEST['username'])) error_msg('No username included!', 'Please press the back button on your browser to go back to the previous page to include a username.', 'Y', 'Y');
if ($_REQUEST['password'] == '' | $_REQUEST['password'] == ' ' | empty($_REQUEST['password'])) error_msg('No password included!', 'Please press the back button on your browser to go back to the previous page to include a password.', 'Y', 'Y');
if ($_REQUEST['password2'] == '' | $_REQUEST['password2'] == ' ' | empty($_REQUEST['password2'])) error_msg('No second password included!', 'Please press the back button on your browser to go back to the previous page to include a second password.', 'Y', 'Y');
if ($_REQUEST['contact'] == '' | $_REQUEST['contact'] == ' ' | empty($_REQUEST['contact'])) error_msg('No Contact Information!', 'Please make sure you selected to have people contact you or not.', 'Y', 'Y');
if ($_REQUEST['email'] == '' | $_REQUEST['email'] == ' ' | empty($_REQUEST['email'])) error_msg('No email included!', 'Please press the back button on your browser to go back to the previous page to include a email address.', 'Y', 'Y');
if (!check_email_mx($_REQUEST['email'])) error_msg('Invalid E-mail Address!', 'Please make sure you have spelled your E-Mail address right.', 'Y', 'Y');
if ($_REQUEST['password'] != $_REQUEST['password2']) error_msg('Passwords don\'t match!', 'Please press the browsers back button to fix this error.', 'Y', 'Y');
$check = mysql_query('SELECT username, email FROM voxrank_users');
while ($i = mysql_fetch_assoc($check)) {
if ($_REQUEST['username'] == $i['username']) error_msg('Username All Ready Registered!', 'Please press the browser back button and register another username because the one you wish to use is all ready in the database.', 'Y', 'Y');
if ($_REQUEST['email'] == $i['email']) error_msg('E-Mail All Ready Registered!', 'Please press the browser back button and registrar another email address because the one you wish to use is all ready in the database.  If you have all ready registered, please <a href="lost.php">click here</a> to get your username and password.', 'Y', 'Y');
}
}

function check_site_info() { // This function is used to check the websites input information
  global $user_id, $website_name, $website_info, $_REQUEST, $website_banner_url, $banner, $button, $max_banner_width, $max_banner_height, $cat, $use_cats, $free_vote, $main_site, $site_id;
  if ($_REQUEST['website_name'] == '' | $_REQUEST['website_name'] == ' ' | empty($_REQUEST['website_name'])) error_msg('No Web site Name included!', "Please press the back button on your browser to go back to the previous page to include a web site name.", 'Y', 'Y');
  if ($_REQUEST['website_info'] == '' | $_REQUEST['website_info'] == ' ' | empty($_REQUEST['website_info'])) error_msg('No Web Site Information included!', "Please press the back button on your browser to go back to the pervious page to include web site information.", 'Y', 'Y');
  if ($_REQUEST['website_url'] == '' | $_REQUEST['website_url'] == ' ' | empty($_REQUEST['website_url'])) error_msg('No Web site URL included!', "Please press the back button on your browser to go back to the previous page to include a web site URL.", 'Y', 'Y');
  if ($_REQUEST['cat'] == '' | $_REQUEST['cat'] == ' ' | empty($_REQUEST['cat'])) error_msg("No Web site Category included!", "Please press the back button on your browser to go back to the pervious page to include a web site category.", 'Y', 'Y');

  if ($_REQUEST['website_banner_url'] == '' | $_REQUEST['website_banner_url'] == ' ' | empty($_REQUEST['website_banner_url'])) $banner = 'http://'; else $banner = $_REQUEST['website_banner_url'];
  if ($_REQUEST['website_button_url'] == '' | $_REQUEST['website_button_url'] == ' ' | empty($_REQUEST['website_button_url'])) $button = 'http://'; else $button = $_REQUEST['website_button_url'];

  if ($banner != 'http://') {
  $image = @getimagesize($banner) or error_msg("Could not connect to image!", "Please press the back button on your browser to go back to the pervious page to make sure the URL is correct for your banner.", 'Y', 'Y');
  if ($image[0] > $max_banner_width | $image[1] > $max_banner_height) error_msg("Banner image is too big!", "Please press the back button on your browser to go back to the pervious page to include a bit smaller banner.", 'Y', 'Y');
  }

}

function insert_new_site() { // This function is used to inset a new website into the database
global $user_id, $cat, $free_vote, $main_site, $site_id, $website_name, $banner, $button, $website_info, $website_url, $website_banner_url, $website_button_url;
$website_name = htmlentities ($website_name, ENT_QUOTES);
$website_info = htmlentities ($website_info, ENT_QUOTES);
mysql_query("INSERT INTO voxrank (id, name, info, url, bannerurl, buttonurl, user_id, cat) VALUES ('".$site_id."', '".$website_name."', '".$website_info."', '".mysql_real_escape_string(check_input($_REQUEST['website_url']))."', '".$banner."', '".$button."', '".$user_id."', '".mysql_real_escape_string(check_input($_REQUEST['cat']))."')");
}

function insert_new_user() { // This function is used to insert a user into the database
global $username, $contact, $password, $email, $user_id, $prefix, $salt_key;
$cookiename = $prefix.'_user_id';
$cookiename2 = $prefix.'_username';
$cookiename3 = $prefix.'_password';
setcookie($cookiename, $user_id);
setcookie($cookiename2, $username);
setcookie($cookiename3, md5($password));
mysql_query("INSERT INTO voxrank_users (id, username, password, email, contact) VALUES ('".$user_id."', '".mysql_real_escape_string(check_input($_REQUEST['username']))."', MD5('".$salt_key."".mysql_real_escape_string(check_input($_REQUEST['password']))."'), '".mysql_real_escape_string(check_input($_REQUEST['email']))."', '".mysql_real_escape_string(check_input($_REQUEST['contact']))."')");
}

function checkip() { // This function is called on all pages to block someone from view the website or voting
global $ip;
	// Get persons IP address
	$ip = getenv('REMOTE_ADDR');
	if (!$ip) $ip = getenv('REMOTE_HOST');

	$xx = mysql_query("SELECT * FROM voxrank_ips WHERE ip = '".$ip."'");
	while ($x = mysql_fetch_assoc($xx)) {
		if ($x['fullbann'] == 'Y') error_msg('You Have Been Banned!', "You have got this error because your IP address has been listed to be banned from seeing this site.", 'Y', 'Y');
		if ($x['novote'] == 'Y') {
		header('Location: index.php');
		die;
		}
	}
}


function resetlist() { // This function will zero all hits in and hits out of the database table
global $days_to_reset;
$nextresetdate = (86400 * $days_to_reset) + time();
$lastreset = time();
mysql_query("UPDATE voxrank_settings SET nextreset='$nextresetdate', lastreset='$lastreset' WHERE id='1'") or die(mysql_error());
mysql_query('UPDATE voxrank SET hitsin=0, hitsout=0') or die(mysql_error());
}

require_once 'functions2.php';
?>
Return current item: VoxRank