Alright, here's my config file after conversion of the statements. The page executes without errors and arrays contain what they're supposed to but just wanted to make sure that I'm handling things like making sure $cookie is safe when used in a statement. Any thoughts on improvement would be most welcome. I'll carry what I learn over to the next page in line for conversion.
<?php
/* File: /includities/configlio.php */
if(!defined('parentInclude')) {
header("Location: /");
exit;
}
// Enable us to use Headers
ob_start();
// Set sessions
if(!isset($_SESSION)) {
session_start();
}
/* Any session setup */
if(!isset($_SESSION['badapple'])){
$_SESSION['badapple'] = 0;
}
/* DB creds */
/* Connect to the DB */
try {
$pdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpasswd);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
/* Query to get necessary settings for general use. */
$stmt = $pdo->query("SELECT * FROM settings LIMIT 1");
$settings1 = $stmt->fetch();
$is_online = $settings1['is_online'];
$offline_excuse = $settings1['offline_excuse'];
$site_title = stripslashes($settings1['title']);
$site_description = stripslashes($settings1['description']);
$site_keywords = stripslashes($settings1['keywords']);
/* Site specific shite*/
$site_cookie = 'bicyclio_user';
$site_url = 'https://bicyclio.com';
$site_name = 'Bicyclio!';
$site_email = 'its@schw.im';
$rightnow = time();
$token = mt_rand().$rightnow;
$pubtoken = substr(session_id(), 0, 10);
$alert = array();
$alert_display = '';
if(isset($_COOKIE[$site_cookie])){
/* User has a cookie. Is it valid?*/
$stmt = $db->prepare("SELECT * FROM users WHERE cookie=:cookie LIMIT 1");
$user = $stmt->bindParam(':cookie', $_COOKIE[$cookie_name], PDO::PARAM_STR);
if ($user->rowCount() > 0) {
$vu_id = $user['user_id'];
$vu_sid = session_id();
$vuname = $user['username'];
$vu_email = $user['user_email'];
$vu_group_id = $user['group_id'];
$vu_role = $user['role'];
$vu_avatar = $user['avatar'];
if($vu_avatar == ''){
$vu_avatar = 'no_avatar.png';
}
}else{
/* Has a cookie but isn't legitimate */
$is_anon = '1';
}
}else{
/* Doesn't have a cookie */
$is_anon = '1';
}
if($is_anon){
/* No cookie means visitor is anonymous */
$vu_username = 'Anonymous';
$vu_id = '0';
$vu_sid = session_id();
$vu_group_id = '1'; // 6 eqals bot
$vu_role = 'user';
$vu_avatar = 'anonymous.png';
}
//Get the forwarded IP if it exists
IF(array_key_exists('X-Forwarded-For', $_SERVER) && filter_var($_SERVER['X-Forwarded-For'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)){
$vu_ip = $_SERVER['X-Forwarded-For'];
$vu_proxy = $_SERVER['REMOTE_ADDR'];
}ELSEIF(array_key_exists('HTTP_X_FORWARDED_FOR', $_SERVER) && filter_var($_SERVER['HTTP_X_FORWARDED_FOR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)){
$vu_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
$vu_proxy = $_SERVER['REMOTE_ADDR'];
}ELSE{
$vu_ip = filter_var($_SERVER['REMOTE_ADDR'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
}
?>