Archive for July, 2009

Accessing other frame data

In your main page you have an iframe. The iframe code is:

<input type=”text” value=”andy” name=”myname”>

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:

<script>
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()”>

, , , , , , ,

No Comments

Prevent sql injection code

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:

function checkValid($str)
{
$valid_string = “[\*\^\'\;]“;
if(ereg($valid_string,$str))
{
echo(”<script>alert(’Invalid characted’);</script>”);
die();
}
else
{
return $str;
}
}

, , , , , , , , , ,

No Comments

PHP Obfuscator

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

, , , , , , , , , , , , ,

1 Comment

How to make wordpress plugin: General

This article will present you with the basics of wordpress plugin. I have create a plugin to help you understand how to create a plugin. This simple plugin shows a digg button to all your post. You can download the full code here. Below is several code I use:

class diggme
{
function diggme() {

add_action(’init’, array($this, ‘init’));
add_action(’admin_menu’, array(&$this, ’setmenu’));
add_filter(’the_content’, array(&$this, ‘the_content_filter’));
}

function init()
{
?>
<link href=”<?php echo get_option(’siteurl’); ?>/wp-content/plugins/diggme/css.css” rel=”stylesheet” type=”text/css” />
<?php
}

function managepage(){
echo “<div id=’setting’>This is setting page. Just ignore this</div>”;
}

function setmenu () {
add_options_page(
‘DiggMe’,
‘DiggMe’,
‘manage_options’,
__FILE__,
array(&$this,’managepage’ ) );
}

function the_content_filter($content)
{
return $this->displaydigg() . $content;
}

function displaydigg()
{
global $post;

return “<div id=\”diggbutton\”><a href=\”http://digg.com/submit?phase=2&amp;url=”.get_permalink($post->ID).”\”><img src=\”".get_settings(’siteurl’).”/wp-content/plugins/diggme/digg.png\”></a></div>”;
}

}

$diggme = new diggme();

  • The code will first create a class called diggme. Every time the plugin loads it will create an object of this class using $diggme = new diggme();

The constructor

  • add_action(’init’, array($this, ‘init’)); -> This will tell your blog to execute function init whenever it loads.
  • add_action(’admin_menu’, array(&$this, ’setmenu’)); -> This will tell your blog to create menu at your admin page. You can place any settings here.
  • add_filter(’the_content’, array(&$this, ‘the_content_filter’)); -> This will be executed every time when your post loads. In this example we will load function the_content_filter every time the page loads, read the post content and add a digg button to the post.

Other function is easy to understand if you have basic PHP skill. If you have any question just comment below.

, , , , , , , , , , , , , , , , , , , ,

1 Comment

Show and Hide with jquery

With jQuery, you can show and hide div. The implementation is really cool. With jQuery you can show and hide with various functions:

  • show(”fast”) , show(”slow”), show(400). The 400 is in mili seconds
  • hide(”fast”) , hide(”slow”), hide(400). The 400 is in mili seconds
  • slideUp()
  • slideDown()
  • slideToggle()
  • fadeIn()
  • fadeOut()

You can see the demo here and download the code here.

, , , , , , , , , ,

No Comments

IE6 css bug

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:

div {
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.

, , , , , , , , , , , , , , , , ,

No Comments

Joomla detect if home page

To detect if current page is Joomla hage page, do this code:

<?php
$uri = $_SERVER['REQUEST_URI'];
if ($uri == “/”) {
echo “You’re on the homepage”;
}
?>

, , , , , ,

1 Comment

Show code to wordpress home only

Use this code to show only to home page only on wordpress:

<?php if (is_home()) : ?>

//your code here

<?php endif; ?>

, , , ,

No Comments

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:

<!–[if lte IE 6]>
<style type=”text/css” media=”screen”>
@import “ie.css”;
</style>
<![endif]–>
if lte IE 6 means if browser is lower than equal (lte) IE 6. If you want to use the css specifically to IE 6 then:  <!–[if IE 6]>. There are also gte (greater then equal) for browser above or equal a spesific browser. Here’s the summary:
  • 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
Download the full code here.

, , , , , , , , , , , , ,

1 Comment