BlogNest of "mul14"


Membuat RSS Feeds

Ditulis dalam Development, Internet, PHP, Web, komputer oleh mul14 pada 2009-Juli-10
Tags: , ,

Tambahkan pada <head>

<head> <link rel="alternate" type="application/rss+xml" href="http://url-php-anda/rss.php" /> </head>

Struktur XML

<?xml version=”1.0″ ?>
<rss version=”2.0″>
<channel>
<title>Judul Pertama</title>
<link>http://www.url-anda.com/page/1</link>
<description>Hallo ini ada lah judul pertama hehehe..</description>
</channel>
<channel>
<title>Judul kedua</title>
<link>http://www.url-anda.com/page/2</link>
<description>Kalo yang ini yang kedua</description>

</channel>

</rss>
<?xml version="1.0" ?>

<rss version="2.0">

  <channel>

   <title>Judul Pertama</title>

    <link>http://www.url-anda.com/page/1</link>

    <description>Hallo ini ada lah judul pertama hehehe..</description>

  </channel>

  <channel>

   <title>Judul kedua</title>

    <link>http://www.url-anda.com/page/2</link>

    <description>Kalo yang ini yang kedua</description>

  </channel>

</rss>

Kalau ada gambar, tambahkan didalam <channel>

<image>     <url>http://www.url-anda.com/hola.gif</url>     <link>http://www.url-anda.com/page/1</link> </image>

Ini tutorial bikin blog simple pake Kohana

Ditulis dalam Development, Internet, PHP, Web, komputer oleh mul14 pada 2009-Juni-29
Tags: , , , ,

Diambil dari kohana-id@googlegroups.com

Blog nya ini simple banget.. cuma CR… bukan CRUD…
Semoga bisa sedikit membantu buat yang baru belajar Kohana..

Isi file application/controllers/welcome.php

<?php
class Welcome_Controller extends Template_Controller {
  public $template = 'template'; // View yang terdapat pada 'views/template.php'

  public function __construct() {
    parent::__construct();
    $this->template->menus = array('Home'=>'welcome',
                                   'Article'=>'welcome/article',
                                   'Post'=>'welcome/post');
  }
  public function index() {
    $this->template->content = 'Ini Home';
  }
  public function article () {
    $this->template->content = new View ('article');
    $db = ORM::factory('article');  $data = $db->orderby('sent','DESC')->find_all();
    $this->template->content->isi = $data;
  }
  public function post () {
    $this->template->content = new View ('post');
  }
  public function save () {
    $db = ORM::factory('article');
    $db->subject = $_POST['subject'];
    $db->message = $_POST['message'];
    $db->sent = date('Y-m-d H:i:s');
    $db->save();
    url::redirect('welcome/article');
  }
}

Isi file application/views/template.php

<html>
  <head>
  <title>Simple Blog with Kohana</title>
  <style>
  body {
    background: black;
    color: #fff;
    font-family: Arial, sans-serif;
    font-size: 14px;
  }
  a, a:visited {
    color: orange;
    text-decoration: none;
  }
  a:hover {
    color: gold;
  }
  #wrapper {
    width: 760px;
    margin: auto;
  }
  input, textarea {
    display: block;
  }
  .sent {
    color: #333;
  }
  #menu li {
    margin-right: 10px;
    display: inline;
  }
  .float-left {
    float: left;
  }
  .float-right {
    float: right;
  }
  .clear {
    clear: both;
  }
  .center {
    text-align: center;
  }
  </style>
</head>
<body>
  <div id="wrapper">
  <div id="header"><h1>Simple Blog with Kohana</h1></div>
  <ul id="menu">
    <?php foreach ( $menus as $menu => $url ): ?>
    <li><?php echo html::anchor($url, $menu) ?></li>
    <?php endforeach ?>
  </ul>
  <div id="content"><?php echo $content ?></div>
  <div id="footer">Copyright&copy; 2009 mul14</div>
  </div>
</body>
</html>

Isi file application/views/article.php

<?php foreach ($isi as $v): ?>
<h2><?php echo $v->subject ?></h2>
<div>Sent: <?php echo $v->sent ?></div>
<div><?php echo $v->message ?></div>
<?php endforeach ?>

Isi file application/views/post.php

<?php
echo form::open('welcome/save');
echo form::label('subject', 'Subject') . form::input('subject');
echo form::label('message', 'Message') . form::textarea('message');
echo form::submit('send', 'Send');
echo form::close();
?>

Isi file application/models/article.php

<?php
class Article_Model extends ORM {}

MySQL nya:

CREATE TABLE IF NOT EXISTS `articles` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`subject` tinytext CHARACTER SET utf8 NOT NULL,
`message` text CHARACTER SET utf8 NOT NULL,
`sent` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;
INSERT INTO `articles` (`id`, `subject`, `message`, `sent`) VALUES
(1, 'Vestibulum hendrerit', '<p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Maecenas nisi. Praesent pharetra augue quis magna. Nulla eros. Donec quis urna in lorem nonummy iaculis. Suspendisse tempor venenatis mauris. Cras pulvinar purus id leo posuere imperdiet. Duis aliquam elementum ipsum. Proin non leo. Aliquam erat volutpat. Etiam ultricies pede eget nulla.</p>\r\n', '2009-06-28 03:15:16');

Jangan lupa sesuaikan isi application/config/config.php

PHP Output Buffer

Ditulis dalam Development, PHP, Tips & Tricks, Web oleh mul14 pada 2007-November-2

Ini Tips buat para newbies yang jengkel kalo pake session ato header() sering muncul tulisan Warning: Cannot modify header information – headers already sent by….

Gunakan fungsi output buffer di php.

<?php
echo "Lembu";
session_start();
?>

Biasanya contoh diatas akan muncul error message: Warning: Cannot modify header information – headers already sent by….
Sekarang coba gunakan ini:

<?php
ob_start();
echo "Lembu";
session_start();
ob_end_flush();
?>

Masalah terpecahkan.. :)

Get Screenshot with PHP

Ditulis dalam Internet, PHP, Tips & Tricks, Web oleh mul14 pada 2007-September-14

Kemarin abis download PHP Manual yang baru. Lalu aku isenk baca PHP Manual: Migrating from PHP 5.1.x to PHP 5.2.x. Ternyata cukup banyak juga perubahan. Dan beberapa ada yang tidak compatible dengan versi sebelum-nya.

Tapi dua function baru yang menurut saya sangat menarik. Yaitu imagegrabscreen() dan imagegrabwindow(). Kedua function ini ada mulai PHP versi 5.2.2.

Sekarang dengan, anda bisa mengambil screenshot user server. Caranya:

<?php
$im = imagegrabscreen();
imagepng($im, "myscreenshot.png");
?>

Sayangnya kedua function ini ada bekerja pada platform Windows. Semoga nantinya juga bisa bekerja di platform Unix/Linux, mengingat Unix/Linux banyak digunakan pada server.


Ralat, ternyata function ini bekerja di server-side. Jadi gambar yang diambil hanya gambar yang sedang dibuka di server.

OS Detection with PHP

Ditulis dalam Development, Internet, PHP, Web oleh mul14 pada 2007-September-8

Terkadang beberapa programmer PHP yang masih newbie, ingin mengetahui OS apa yang sedang digunakan user. Dari beberapa yang saya temui, ada yang menggunakan $_SERVER['HTTP_USER_AGENT'], lalu menggunakan str_pos, if-else/switch, dsb..

Sebenarnya function untuk urusan ini udah ada didalam core php (built-in function).

Berikut caranya yang lebih simple, hanya dua baris.

<?php
$browser = get_browser(null, true);
echo $browser['platform']; //output: WinXP
?>
Halaman Berikutnya »