Posts Tagged Echo
Prevent sql injection code
Posted by in PHP code on July 23rd, 2009
SQL Injection is a technique where an attacker creates or alters existing SQL commands to tamper data, override valuable ones, or even to execute dangerous system level commands on the database host. To avoid this, always check your input data using the function below:
{
$valid_string = “[\*\^\'\;]“;
if(ereg($valid_string,$str))
{
echo(”<script>alert(’Invalid characted’);</script>”);
die();
}
else
{
return $str;
}
}
Joomla detect if home page
Posted by in PHP code on July 19th, 2009
To detect if current page is Joomla hage page, do this code:
$uri = $_SERVER['REQUEST_URI'];
if ($uri == “/”) {
echo “You’re on the homepage”;
}
?>
Set cookie with php
Posted by in PHP code on June 14th, 2009
Here’s the code to set and get cookie
<?php
//set cookie
setcookie(”Cookie1″, $value);
setcookie(”Cookie2″, $value, time()+3600);
//get cookie
echo $_COOKIE["Cookie2"];
?>









