[ create a new paste ] login | about

Link: http://codepad.org/gAdRdbBc    [ raw code | fork ]

Kalob - PHP, pasted on Dec 10:
<?php
	function Post()
	{
		return $_SERVER['REQUEST_METHOD']=="POST";
	}
	function cleanMySQL($var)
	{
		$var = mysql_real_escape_string($var);
		return $var;
	}	
	function Back()
	{
		if(isset($_SERVER['HTTP_REFERER'])) 
		{
			header("Location: " . $_SERVER['HTTP_REFERER']);
		}
	}
	function LoggedIn()
	{
		if(isset($_SESSION['UID']) && $_SESSION['UID']!='')
			return true;
		else
			return false;
	}
	function UserPic($UID, $w=50, $h=50, $link=1, $b=0, $id=NULL, $css=NULL, $e=NULL) {
		// w = width
		// h = height
		// link = link 2 profile
		// b = border around image - keep as 0
		// id = image id
		// css = any css classes
		// e = extra styling
		$UID = cleanMySQL($UID); // always clean it!
		$from = mysql_query("SELECT UID, Sex, Pic FROM Profiles WHERE UID='$UID'") or die(mysql_error($con));
		if($from) {
			$fetch = mysql_fetch_array($from);
			if(!empty($fetch['Pic'])) {
				$Pic = "images/uploads/".$fetch['Pic'];
			} else {
				if($fetch['Sex']==1) {
					$sex = "female";
				} else { 
					$sex = "male";
				}
				$Pic = "images/profiles/".$sex."_small.gif";
			}
		} else {
			$Pic = NULL; // makes sure this variable is set (isset())
		}
		if($link) {
			$linkStart = "<a href='profile.php?id=".$UID."'>";
			$linkEnd = "</a>";
		} else {
			$linkStart = NULL;
			$linkEnd = NULL;
		}
		if(!empty($id)) {
			$id = " id='".$id."'";
		}
		if(!empty($css)) {
			$css = " class='".$css."'";
		}
		if(!empty($e)) {
			$e = " style='".$e."'";
		}
		$img = $linkStart . "<img src='$Pic' border='".$b."' width='".$w."' height='".$h."'".$id.$css.$e." />" . $linkEnd;
		return $img;
	}
	function UserName($UID, $link=1, $css=NULL, $id=NULL) {
		$UID = cleanMySQL($UID); 
		$find = mysql_query("SELECT UID, Firstname, Lastname FROM Profiles WHERE UID='$UID'") or die(mysql_error());
		if(mysql_num_rows($find)==1) {
			$User = mysql_fetch_array($find);
			$Name = $User['Firstname'] . " " . $User['Lastname'];
			if(!empty($css)) {
				$css = " class='".$css."'";
			}
			if(!empty($id)) {
				$id = " id='".$id."'";
			}
			if($link) {
				$return = "<a href='profile.php?id=".$UID."'".$id.$css.">".$Name."</a>";
			} else {
				$return = "<span".$id.$css.">".$Name."</span>";
			}
		}
		return $return;
	}
?>


Create a new paste based on this one


Comments: