Archive for July, 2009
Accessing other frame data
Posted by in PHP code on July 29th, 2009
In your main page you have an iframe. The iframe code is:
To access the data from that iframe the syntax will be :
Formname.document.getElementsByName.(’contaolname’)[0].value
So the code for the main file is:
function getvalue()
{
alert(frame1.document.getElementsByName(’myname’)[0].value);
}
</script>
<iframe src=”form.php” name=”frame1″></iframe>
<input type=”button” value=”Get value” onclick=”getvalue()”>
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;
}
}
Login form with PHP
Posted by in PHP code on July 23rd, 2009
- First you need to create table for your user with fields: username and password.
- Create basic HTML form that user will fill username and password. This should be easy.
- The action form should should then check whether username and password is valid or not from database. You can encrypt the password using md5 functions. When you check the password supplied by user you need to md5 it too with the value stored in database.
- If user successfully login, then register session and redirect them to other page, like the admin page. The code to register session and redirect them is:
session_register(”password”);
header(”location:admin.php”);
- When user logout you must delete the session:
session_destroy();
PHP Obfuscator
Posted by in PHP code on July 23rd, 2009
Obfuscation allows you to scramble your PHP code so it is hard to read by humans. One of the best Obfuscation for PHP I know is PHP Obfuscator.
Unlike some other solutions PHP Obfuscator does not require special server side libraries or server components to work properly. This allows you to target a broad range of servers that support PHP. This may be useful for commercial products looking to secure their source code.
Key Features
-
Encode and obfuscate PHP code, functions and variables
-
Exclude particular variables, functions or files from obfuscation and encoding
-
Process large projects with command line tools and project files
-
Open source and 100% free
IE6 css bug
Posted by in CSS on July 20th, 2009
In general if a div width is not set, the div box is as wide as the content within it. If there is padding, borders, or margins, this will be added to the box width. So, a 100px box with 0 padding and 0 border would have 100px width and will render the same in IE and Mozilla. But, if 5px padding is added, the Mozilla box would be 110px wide. 100px + 5px left padding + 5px right padding = 110px wide. While the IE box would still be 100px.
So Internet Explorer does not render the div box correctly. To have the same look on different browser, you need to hack your css for IE browser.
You can do the below code:
width: 100px;
padding: 5px;
}
* html div {
\width: 110px;
}
The first div will work on Firefox and the second div won’t work on Firefox but will work on IE.
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”;
}
?>
Show code to wordpress home only
Use this code to show only to home page only on wordpress:
//your code here
<?php endif; ?>
How to use different css on different browser
Cross Browser Compatibility is a huge issue in the website development with many browsers in the market. But luckily most of them uses Internet Explorer and Firefox. Sometimes different version of browser also have different output like the display in IE8 and IE6. To tackle this you can use different css for different browser.
Here’s the code:
<style type=”text/css” media=”screen”>
@import “ie.css”;
</style>
<![endif]–>
- lte IE 6 -> IE 6 and all version lower
- lt IE 6 -> version below IE 6
- IE 6 -> only IE 6
- gt IE 6 -> version higher IE 6
- gte IE 6 -> IE 6 and all version higher









