JAUHARI

Everything Is POSSIBLE

Archive for the ‘How To’


How To: Set Date and Time On Linux

A few days ago I need to reconfigure office proxy server (I am using Squid) to avoid certain users accessing Internet during work hour. Sound extreme huh? But it’s a company policy. I can not deny.

They are not allowed to access during 08:00-12:00 and 13:00-16.30. After configuring and apply the ACL (Access Control List)  to my PC for trial, the ACL did not work. I ever did this before. I just did a copy and paste. It should work. Search result on the Internet to find the right configuration convinced me that mine was correct.

It must be caused by another problem, I guessed. It’s true. I did “touch test” and “ls-l” showed that the file was not created in the correct clock time. The “date” command told that the time on the server was not coorect.

I need to adjust server clock setting. Here is the command.

# date -s ‘MM/DD/YYYY HH:MM:SS’ <– change with actual date and time eg: ‘12/24/2007 16:25:00′

# clock -w  <– to set the hardware clock (CMOS)  to match the kernel time

# echo “clock -s” /sbin/hwclock  <– to make sure that the time is always correct on reboot, link the kernel time to hardware clock

# chmod +x /sbin/hwclock  <– make the script executable

Voila. The time is adjusted and my ACL worked like a charm.

Now, it’s time to wait for the complain :D

How To: Run Multiple Domains On A Local Computer

During web development, sometime you (I always) need to test with a domain name, whether inside local computer or online. This post will tell you how to run multiple domain on your local PC, without setting up a DNS server. I am using Apache 2.0.53.

Case: You want to develop a website for your-domain.com and need to test it online under certain domain name.

Solution:

[1] Create a local domain name

To differ between online and local domain, you need to create a local domain name (sub domain is okay), i.e: local.yourdomain.com

[2] Edit your hosts file

In Windows XP, the “hosts” file can be found at “C:\WINDOWS\system32\drivers\etc”. Put your local domain/subdomain there with the following order:

127.0.0.1 local.yourdomain.com

Hosts File
Continue Reading →

How to Creating the Magical Mirror Effect with Adobe Photoshop

Well, these days, digital photography artists are using mirrors, of sorts, to create magical effects on their computer monitors. Basically, a mirror image is one in which one side of a frame is perfectly mirrored (reflected) on the opposite side of the frame—side to side or top to bottom. In Photoshop, we use Canvas Size, Copy and Paste, Duplicate Layer to create the effect. It’s that easy!

With this technique can do to make text mirrot effect too.

Okay! Let’s take a look at how easy it is to create the magical mirror effect in Photoshop.

Open File

Open file that you want to make a mirror.
Creating the Magical Mirror Effect 1
Continue Reading →

How To Posting by Email in WordPress

Besides the regular style of posting, WordPress also supports different ways of doing this job. For example, you can make posts by mailing to a specific account. This is possible if you set up an email account and make it available to WordPress. For posting by email, let us follow these steps.

Click on the Options menu and then Writing from the sub-menu.

At the bottom of this page, there is a section titled Writing by e-mail. You have to configure some settings before you can start posting by email.

Post Via Email

In this section, you have to provide the Mail server, Login name (usually, that is your full email address), and the Password. Finally, select the category to which these posts should go. That’s it, you are done!

Create a Skinnable Interface with PHP

Have you ever run across a user who just has to have every blog he reads appear in his own personal color scheme? Are you that kind of user? Thankfully, supporting these users is far easier with CSS support in modern browsers.

CSS defines the fonts, colors, sizes, and even positions of elements of a page independent of the HTML code for that page. You can change the look of a single HTML page drastically simply by redefining its CSS stylesheet. This hack shows how to provide user-selectable CSS and offers some advice on creating customizable interfaces.

The XHTML Code


< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  < ?php
  $style = "default";
  if ( $_GET["style"] )
  $style = $_GET["style"];
  $files = array( );
  $dh = opendir( "styles" );
  while( $file = @readdir( $dh ) )
  {
  if( preg_match( "/[.]css$/", $file ) )
  {
  $file = preg_replace( "/[.]css$/", "", $file );
  $files []= $file;
  }
  }
  ?>
  <style type="text/css" media="all">@import url(styles/< ?php echo($style); ?>.css);</style>
  <title>Custom Style With PHP</title>
  </head>
  <body>
  <div id="wrap">
  <div id="h">
  <h1>Custom Style With PHP</h1>
  </div>

 <div id="left">
  <ul class="menu">
  <li><div class="menu-active"><a href="home.php">Home</a></div></li>
  <li><div class="menu-inactive"><a href="faq.php">FAQ</a></div></li>
  <li><div class="menu-inactive"><a href="contact.php">Contact</a></div></li>
  </ul>
  </div>

  <div id="right">
  Important information

 <div class="box-content">
  Lots of information about important events and
  stuff.
  </div>

</div>
  <br class="clear" />
  <div id="foot">
  <form>
  <h3>Select Style:</h3>
  <select name="style">
  < ?php foreach( $files as $file ) { ?>
  <option value="<?php echo($file); ?>"
  < ?php echo( $file == $style ? "selected" : "" ); ?>>< ?php echo($file); ?> +++++++>&nbsp;&nbsp; 
  </option>
  < ?php } ?>
  </select>
  <input type="submit" value="Select" />
  </form>
  </div></div></body>

 <!– End Wrap –>
  </html>

Continue Reading →

Create Pop-Up Hints with PHP

Use the overLIB library to pop up hints for words on your web page using JavaScript and PHP.

With the overLIB JavaScript library , you can have handy pop-up labels that appear above text on your page. This hack makes it a little easier to create these links by providing a PHP wrapper function to invoke the library.

Complete Code

Save the code shown as pop-up.php.

A wrapper function that simplifies overLIB use, courtesy of PHP


<?php
  function popup( $text, $popup )
  {
  ?>
  <a href="javascript:void(0);" onmouseover="return overlib(’<?php echo($popup); ?>
  ‘);" onmouseout="return nd();"><?php echo($text); ?></a>
  <?php
  }
  ?>
  <html>
  <head>
  <script type="text/javascript" src="overlib/overlib.js"><!– overLIB (c) Erik Bosrup –>
  </script>
  </head>
  <body>
  <div id="overDiv" style="position:absolute; visibility:hidden; z-index:1000;">
  </div>
  With PHP, we can combine with some javascript to make small popups. <br />Just hover your mouse on <?php popup(
  ‘me’, ‘And this is The Hover Text.<br/>Looking Wonderfull ha?.’
  ); ?>. It’s work ^_*.
  </body>
  </html>

You could also put the wrapper function into a PHP library, include that library in your PHP pages, and turn this into a nice, reusable utility function.

Test Your Code

Download and unpack the overLIB library into your web server’s documents directory. Then add in the pop-up.php file and test it on your browser, You should see something similar

PHP Popups Screen shoot 1

Next, move the mouse over the word me, and you will see the pop up appear, which gives you a little more information about me

PHP Popups Screen shoot 2

This pop up can be as elaborate as you like, with images, tables, different fonts, styles, and whatever else you want it.

How To Parsing a Simple XML Document in PHP

Here is an example of an XML document and the steps needed to parse that document:

test.xml — The XML file we parse.

<?xml version="1.0"?>
<book>
<chapter id="1">
<title>Chapter 1</title>
<contents>
The Contents of chapter one go here.
</contents>
</chapter>
<chapter id="2">
<title>Chapter 2</title>
<contents>
The Contents of chapter two go here.
</contents>
</chapter>
</book></code>

xml-test.php — The PHP program to parse the XML file.

<?php
function start_element($parser, $element_name, $element_attrs)
{
switch ($element_name) {
case "CHAPTER":
print "<a name=\"#$element_name{$element_attrs['ID']}\"></a>";
break;

case "TITLE":
print ‘<h2>’;
break;

case "CONTENTS":
print ‘<font face="arial" size="2">’;
break;
}
}

function end_element($parser, $element_name) {
switch ($element_name) {
case "TITLE":
echo "</h2>\n";
break;

case "CONTENTS":
echo "</font>\n<br><br>";
break;
}
}
function character_data($parser, $data) {
echo $data;
}

$parser = xml_parser_create();
xml_set_element_handler($parser, ’start_element’, ‘end_element’);
xml_set_character_data_handler($parser, ‘character_data’);
$fp = fopen(’test.xml’, ‘r’) or die(’Cannot open test.xml’);

while ($data = fread($fp, 4096)) {
xml_parse($parser, $data, feof($fp))
or die(sprintf(’XML Error: %s at line %d’,
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
}
xml_parser_free($parser);
?>

PHP connects to the Expat C API, so if you have used Expat before, the example in the synopsis should look somewhat familiar. If you haven’t used Expat before, let me explain a little bit about the theory involved in parsing XML documents.

Expat uses a SAX-type XML parser, meaning that it uses handlers for the different types of events that may occur. When an event occurs, the data is passed to these different handlers, along with information related to the data. Let’s consider the XML document in the preceding “Technique” section: On the start of an element ( would be an element), PHP sends the element name (that is, the title) and any attributes (in array form) related to the start tag to the start_element() function. The start_element() function is defined as the handler for start elements by the xml_set_handler() function.</p> <p>After you have defined your handlers, you can use the xml_parse() function to parse the XML data either in separate chunks (as done here) or all at once. The xml_parse() function returns true on success and false on failure, so you can check whether any errors occurred. When you are done parsing the document, free the parser allocated by the xml_parser_create() function.</p> <p>This is essentially what is done to parse XML documents in PHP with the Expat library. There are a few tricks and a couple more functions, but the idea is basically the same: create the parser, create the handlers, set the handlers, and then parse the document.</p> <p><em>src: PHP Developer’s Cookbook, Second Edition</em>

  • Archives

  • High Quality Free WordPress Themes
  • Earn $$ with WidgetBucks!
  • Your Ads Here