$val) { if (!is_array($val)) { $val = stripslashes($val); $val = ereg_replace('\\|\\\\','',$val); $val = ereg_replace("'","\'",$val); $val = str2htmlentity($val); $_POST[$key] = $val; ${$key} = $val; } } //sendEmailNotification('Someone Posted'); } foreach( $_GET as $key => $val) { if (!is_array($val)) { $val = stripslashes($val); $val = ereg_replace('\\|\\\\','',$val); $val = ereg_replace("'","\'",$val); $val = str2htmlentity($val); $_GET[$key] = $val; ${$key} = $val; } } /* * Load / create various classes and functions */ require_once("Data.class"); # Initialize data class require_once("Page.class"); # Initialize page class /* * This function will provide an email containing all session, POST and GET * information when called (see form input cleaning function above) */ function sendEmailNotification($subject='Email From Website') { $email_body = "This is the session data:\n\n"; foreach( $_SESSION as $key => $val) { $email_body .= ' ' . $key . ': ' . $val . "\n"; } $email_body .= "\n"; $email_body .= "This is the post data:\n\n"; foreach( $_POST as $key => $val) { $email_body .= ' ' . $key . ': ' . $val . "\n"; } $email_body .= "\n"; $email_body .= "This is the get data:\n\n"; foreach( $_GET as $key => $val) { $email_body .= ' ' . $key . ': ' . $val . "\n"; } $email_body .= "\n"; $email_body .= "This is the server, browser and connection information:\n\n"; foreach( $_SERVER as $key => $val) { $email_body .= ' ' . $key . ': ' . $val . "\n"; } include_once('Email.class'); $email = new Email('tony@awtrey.com','webmaster@awtrey.com',$subject,$email_body); $email->send(); } /* * Yes, I know PHP has a built-in function that does this. It has some oddness * depending on the version of PHP amoung other issues. See the PHP Manual * for lots of people offering their version of an entity conversion script. * I just want the 4 items here converted, so I did just wrote a function that * does only what I want it to do. */ function str2htmlentity($string) { $string = ereg_replace('"', '"', $string); $string = ereg_replace('<', '<', $string); $string = ereg_replace('>', '>', $string); $string = ereg_replace('&', '&', $string); return($string); } function htmlentity2str($string) { $string = ereg_replace('"', '"', $string); $string = ereg_replace('<', '<', $string); $string = ereg_replace('>', '>', $string); $string = ereg_replace('&', '&', $string); return($string); } /* * This is a handy function that truncates a string of text at the first space * character before the specified length. */ function truncate_string($string,$length='300') { if ( strlen($string) > $length ) { $string = preg_replace('/\s+?(\S+)?$/', '', substr($string, 0, $length+1)); return substr($string, 0, $length); } else { return $string; } } /* * Function to properly handle HTTP Location: redirects. */ function redirect($location='') { if ( $location == '' ) { $location = RELPATH; } header("HTTP/1.1 302 Moved Temporarily"); header("Location: $location"); header("Connection: close"); exit; } /* * Site login function */ function login($inLogin,$inPassword) { $account = new Data("account"); if ( $login = $account->return_array("SELECT * FROM account WHERE login='$inLogin' AND password='$inPassword'") ) { $_SESSION['login'] = $login[0]['id']; return true; } else { return false; } } /* * Site logout function */ function logout() { if ($_SESSION['login']) { $_SESSION = array(); if (isset($_COOKIE[session_name()])) { setcookie(session_name(), '', time()-42000, '/'); } session_destroy(); } } /* * Just like print_r but returns a string instead echoing directly to the browser */ function print_readable($pr_var, $pr_ret = false, $pr_level = 0) { $pr_prefix = str_repeat(" ", $pr_level * 4); if ((is_array($pr_var)) or (is_object($pr_var))) { if ($pr_level == 0) { $pr_base = true; if (is_array($pr_var)) { $pr_ret = $pr_prefix . "Array\n"; } else { $pr_ret = $pr_prefix . get_class($pr_var) . " Object\n"; } $pr_ret .= $pr_prefix . "(\n"; $pr_level += 1; $pr_prefix = str_repeat(" ", ($pr_level) * 4); } else { $pr_base = false; $pr_level += 1; $pr_prefix = str_repeat(" ", ($pr_level) * 4); $pr_ret .= $pr_prefix . "(\n"; $pr_level += 1; $pr_prefix = str_repeat(" ", ($pr_level) * 4); } foreach($pr_var as $pr_var_key=>$pr_var_value) { $pr_ret .= $pr_prefix . '[' . $pr_var_key . "] => "; if (is_array($pr_var_value)) { $pr_ret .= "Array\n"; $pr_ret .= print_readable($pr_var_value, $pr_print, $pr_level); } elseif (is_object($pr_var_value)){ $pr_ret .= get_class($pr_var_value) . " Object\n"; $pr_ret .= print_readable($pr_var_value, $pr_print, $pr_level); } else { $pr_ret .= $pr_var_value."\n"; } } $pr_level -= 1; $pr_prefix = str_repeat(" ", ($pr_level) * 4); $pr_ret .= $pr_prefix . ")\n"; if ($pr_base = false) $pr_level -= 1; } else { $pr_ret = $pr_prefix."$var\n"; } $pr_ret .= "\n"; if (($level = 0) and ($ret == true)) { return($pr_ret); } else { return($pr_ret); } } ?>