catatan aja ga usah di baca

Posted on Oktober 28, 2008. Filed under: Tutorial Programming | Tag:, , , |

<?php

class xItem {
  var $xTitle;
  var $xLink;
  var $xDescription;
}

// general vars
$sTitle = "";
$sLink = "";
$sDescription = "";
$arItems = array();
$itemCount = 0;

// ********* Start User-Defined Vars ************
// rss url goes here
$uFile = "http://www.wirelessdevnet.com/wirelessnews/rss/dailynews.rss";
// descriptions (true or false) goes here
$bDesc = true;
// font goes here
$uFont = "Verdana, Arial, Helvetica, sans-serif";
$uFontSize = "2";
// ********* End User-Defined Vars **************

function startElement($parser, $name, $attrs) {
  global $curTag;

  $curTag .= "^$name";

}

function endElement($parser, $name) {
  global $curTag;

  $caret_pos = strrpos($curTag,'^');

  $curTag = substr($curTag,0,$caret_pos);

}

function characterData($parser, $data) { global $curTag; // get the Channel information first
  global $sTitle, $sLink, $sDescription;  
  $titleKey = "^RSS^CHANNEL^TITLE";
  $linkKey = "^RSS^CHANNEL^LINK";
  $descKey = "^RSS^CHANNEL^DESCRIPTION";
  if ($curTag == $titleKey) {
    $sTitle = $data;
  }
  elseif ($curTag == $linkKey) {
    $sLink = $data;
  }
  elseif ($curTag == $descKey) {
    $sDescription = $data;
  }

  // now get the items 
  global $arItems, $itemCount;
  $itemTitleKey = "^RSS^CHANNEL^ITEM^TITLE";
  $itemLinkKey = "^RSS^CHANNEL^ITEM^LINK";
  $itemDescKey = "^RSS^CHANNEL^ITEM^DESCRIPTION";

  if ($curTag == $itemTitleKey) {
    // make new xItem    
    $arItems[$itemCount] = new xItem();     

    // set new item object's properties    
    $arItems[$itemCount]->xTitle = $data;
  }
  elseif ($curTag == $itemLinkKey) {
    $arItems[$itemCount]->xLink = $data;
  }
  elseif ($curTag == $itemDescKey) {
    $arItems[$itemCount]->xDescription = $data;
    // increment item counter
    $itemCount++;
  }
}

// main loop
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
if (!($fp = fopen($uFile,"r"))) {
  die ("could not open RSS for input");
}
while ($data = fread($fp, 4096)) {
  if (!xml_parse($xml_parser, $data, feof($fp))) {
    die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
  }
}
xml_parser_free($xml_parser);

// write out the items
?>
<html>
<head>
<title><?php echo ($sTitle); ?></title>
<meta name = "description" content = "<?php echo ($sDescription); ?>">
</head>
<body bgcolor = "#FFFFFF">
<font face = "<?php echo($uFont); ?>" size = "<?php echo($uFontSize); ?>"><a href = "<?php echo($sLink); ?>"><?php echo($sTitle); ?></a></font>
<br>
<br>
<?php
for ($i=0;$i<count($arItems);$i++) {
  $txItem = $arItems[$i];
?>
<font face = "<?php echo($uFont); ?>" size = "<?php echo($uFontSize); ?>"><a href = "<?php echo($txItem->xLink); ?>"><?php echo($txItem->xTitle); ?></a></font>
<br>
<?php
if ($bDesc) {
?>
<font face = "<?php echo($uFont); ?>" size = "<?php echo($uFontSize); ?>"><?php echo ($txItem->xDescription); ?>
<br>
<?php
}
echo ("<br>");
}
?>
</body>
</html>
Iklan
Baca Pos Lengkap | Make a Comment ( 2 so far )

Plugin Wajib Terpenting Di WordPress

Posted on Oktober 27, 2008. Filed under: Tutorial Programming | Tag:, , |

Sebenarnya raden sendiri belum begitu paham tentang wordpress,maka dari itu sambil belajar wordpress raden coba mendokumentasikan informasi penting ini agar bila suatu saat membutuhkanya nggak repot-repot cari lagi.
Bicara tentang plugin,ahir-ahir ini raden disibukan dengan wordpress sampai-sampai posting di blogspotpun jarang,blog walking udah jarang juga,kasih koment apalagi. itu disebabkan karena saking sibuknya utak-atik wordpress dan juga sekarang kan raden sudah kerja jadi waktu ngeNET berkurang. (bah ribet amat,mana pluginya… ^_* V 🙂 )
oke, berikut plugin terpenting di wordpress yang wajib kamu miliki…

  • All In One SEO Pack: Plugin pertama yang wajib dipasang, kita bisa menentukan sendiri judul dan meta tags di setiap artikel kita serta keyword-keyword yang ingin kita masukkan.
  • Google XML Sitemaps: Plugin ini fungsinya yaitu melakukan auto generate xml sitemap, untuk contohnya bisa dilihat disini, dengan begitu kita bisa memasukan sitemap website kita di google webmasters degan mudah.
  • WordPress Related Post:Untuk yang satu ini bisa dilihat hasilnya sewaktu kita melihat suatu artikel yang dibawahnya terdapat tulisan “Related Post” atau “Artikel yang berhubungan”, sedangkan generate yang dilakukan yaitu berdasarkan tags.
  • FD Feedburner: Dengan plugin ini setidaknya kita bisa melakukan track terhadap subcriber.
  • Really Simple Sitemap: Plugin ini dapat membuat halaman sitemap secara otomatis, kita tinggal tambahkan sedikit code langsung jadi sebuah halaman sitemap yang cukup dinamis.

Plugin diatas sangat baik untuk SEO,jurus SEO atau hanya sekedar belajar SEO.

Baca Pos Lengkap | Make a Comment ( 2 so far )

Regular Expression Basic Syntax Reference

Posted on Agustus 7, 2008. Filed under: Tutorial Programming | Tag:, , , , , |

Characters
Character Description Example
Any character except [\^$.|?*+() All characters except the listed special characters match a single instance of themselves. { and } are literal characters, unless they’re part of a valid regular expression token (e.g. the {n} quantifier). a matches a
\ (backslash) followed by any of [\^$.|?*+(){} A backslash escapes special characters to suppress their special meaning. \+ matches +
\Q...\E Matches the characters between \Q and \E literally, suppressing the meaning of special characters. \Q+-*/\E matches +-*/
\xFF where FF are 2 hexadecimal digits Matches the character with the specified ASCII/ANSI value, which depends on the code page used. Can be used in character classes. \xA9 matches © when using the Latin-1 code page.
\n, \r and \t Match an LF character, CR character and a tab character respectively. Can be used in character classes. \r\n matches a DOS/Windows CRLF line break.
\a, \e, \f and \v Match a bell character (\x07), escape character (\x1B), form feed (\x0C) and vertical tab (\x0B) respectively. Can be used in character classes.
\cA through \cZ Match an ASCII character Control+A through Control+Z, equivalent to \x01 through \x1A. Can be used in character classes. \cM\cJ matches a DOS/Windows CRLF line break.
(lebih…)
Baca Pos Lengkap | Make a Comment ( None so far )

Seeing the number of problems and mistakes PHP coders encounter repeatedly I set out to make this list of the 10 most common problems and mistakes done by PHP coders.

Posted on Agustus 7, 2008. Filed under: Tutorial Programming | Tag:, , , |

Seeing the number of problems and mistakes PHP coders encounter repeatedly I set out to make this list of the 10 most common problems and mistakes done by PHP coders.

1. Not escaping entities

It’s basic knowledge; ALL untrusted input (especially user input from forms) has to be sanitized before it is being output.

echo $_GET[‘username’];

Can for instance output:
<script>/*snooping cookie or changing admin password script*/</script>

It is an apparent security risk not to sanitize untrusted data before output. Besides you might end up with pages looking very messy if you do not thread user input the right way.


How to fix it:

Basically you need to convert < , >, ‘ and ” to their proper entities (&lt; , &gt;
, and &quot;) . The functions htmlspecialchars and htmlentities() do the work.

So here is the right way:

echo htmlspecialchars($_GET[‘username’], ENT_QUOTES);

Uncountable scripts carries this problem.

2. Not Escaping SQL input

When querying your database all ways make sure untrusted data gets escaped else your application will be vulnerable to SQL-injections and unreliable, some coders think that they have covered their asses by having magic_quotes on in their php.ini. The problem is that untrusted input can come from other sources than $_GET, $_POST and $_COOKIE (crawling other websites or using input from the database). And what happens if magic_quotes suddenly is set to OFF?

How to fix it:
I recommend setting magic_quotes to off in php.ini or by using .htaccess and then using mysql_real_escape_string() on all variables used in SQL-expressions.

<?php
$sql = “UPDATE users SET
name=’.mysql_real_escape_string($name).’
WHERE id=’.mysql_real_escape_string ($id).'”;
mysql_query($sql);
?>

In PHP5 combined with mysql5 you can also use bindings.

If you leave magic_quotes On you will just have to trust your instinct.

3. Wrong use of HTTP-header related functions: header(), session_start(), setcookie()

Have you ever encountered this warning? “warning: Cannot add header information – headers already sent [….]

Most likely you have either during development or when deploying PHP applications. When your browser downloads a web page the data response from the server is structured in two different parts: The header part and the content part.

The header consist of not visible data such as cookies to be set or if the browser should redirect to another location. The header always comes first.

The content part consists of the visible content HTML, image data and so on.

If output_buffering is set to Off in php.ini your. When the script outputs during execution all header related functions (setcookie(), header(), session_start()) must be called before any output. The problem is when somebody develops on one platform configuration and deploys to another platform configuration, then redirects stops working, cookies and sessions are not being stored…

How to fix it:
The right way is actually very simple make your script call all header related functions before you start any output and set output_buffering = Off in php.ini (at your development platform). If this is a problem on existing scripts you can all ways hack about with the output control functions.

(lebih…)

Baca Pos Lengkap | Make a Comment ( None so far )

Tips modrewrite

Posted on Agustus 6, 2008. Filed under: Tutorial Programming | Tag:, , , |

para dewa2 php pasti udah banyak yang tahu, jadi ini topik khusus untuk para newbie yang pengen buat url kyk di wordpress ( http://blabla.com/archive/2002-19-05/title/bla )

pertama tama, mod_rewrite adalah sebuah module di apache, dan biasanya di package2 php yg ada sekarang (xampp, phptriad, dll) module ini belum di load secara default, jadi kita harus mengenable module ini dulu (dan tenang saja, biasanya di server2 sekarang, module ini sudah dienabled)
cara mengenable module ini adalah dengan membuka file httpd.conf di folder apache. kemudian cari line :

#LoadModule rewrite_module modules/mod_rewrite.so

hapus tanda #

save file, kemudian restart apachenya. Sekarang kita sudah bisa menjalankan mod_rewrite di windows kita 😀

untuk menjalankan mod_rewrite, di folder yang berisi halaman web kita, kita buat file dengan nama .htaccess
mod rewrite harus selalu diawali dengan perintah :

RewriteEngine on

Kemudian kita buat peraturannya. Contohnya :

RewriteRule ^([a-zA-Z]+)/?$ index.php?page=$1

(lebih…)

Baca Pos Lengkap | Make a Comment ( None so far )

« Entri Sebelumnya

Liked it here?
Why not try sites on the blogroll...