JAUHARI

Everything Is POSSIBLE

Archive for the ‘PHP’


Web-Related Variables in PHP

PHP automatically creates variables for all the data it receives in an HTTP request. This can include GET data, POST data, cookie data, and environment variables. The variables are either in PHP’s global symbol table or in one of a number of superglobal arrays, depending on the value of the register_globals setting in your php.ini file.

In PHP 4.2.0 and after, the default setting for register_globals is off. With register_globals off, all the various variables that are usually available directly in the global symbol table are now available via individual superglobal arrays. There is a limited set of superglobals and they cannot be created from a user-level script. The superglobal array to use depends on the source of the variable. Here is the list:

$_GET 

GET-method variables. These are the variables supplied directly in the URL. For example, with http://www.example.com/script.php?a=1&b=2, $_GET['a'] and $_GET['b'] are set to 1 and 2, respectively.

$_POST 

POST-method variables. Form field data from regular POST-method forms.

$_COOKIE 

Any cookies the browser sends end up in this array. The name of the cookie is the key and the cookie value becomes the array value.

$_REQUEST 

This array contains all of these variables (i.e., GET, POST, and cookie). If a variable appears in multiple sources, the order in which they are imported into $_REQUEST is given by the setting of the variables_order php.ini directive. The default is ‘GPC’, which means GET-method variables are imported first, then POST-method variables (overriding any GET-method variables of the same name), and finally cookie variables (overriding the other two).

$_SERVER 

Continue Reading →

Control Structures in PHP

The control structures in PHP are very similar to those used by the C language. Control structures are used to control the logical flow through a PHP script. PHP’s control structures have two syntaxes that can be used interchangeably. The first form uses C-style curly braces to enclose statement blocks, while the second style uses a more verbose syntax that includes explicit ending statements. The first style is preferable when the control structure is completely within a PHP code block. The second style is useful when the construct spans a large section of intermixed code and HTML. The two styles are completely interchangeable, however, so it is really a matter of personal preference which one you use.

Continue Reading →

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.

Dynamic Variables in PHP

Almost Five years I was use PHP as my Web Server Scripting Languange for my Web Application, from simple application until more robust application. And like other Web Server Scripting Languange, there are some variables function that really useful to make my PHP code more usable and easy to understand, one of my favorites is dynamic variables.

How to use dynamic variables in PHP? use my simple tutorial.
Sometimes it is useful to set and use variables dynamically. Normally, you assign a variable like this:

$var = "hello";
Now let’s say you want a variable whose name is the value of the $var variable. You can do that like this:

$$var = "World";

PHP parses $$var by first dereferencing the innermost variable, meaning that $var becomes “hello”. The expression that’s left is $”hello”, which is just $hello. In other words, we have just created a new variable named hello and assigned it the value “World”. You can nest dynamic variables to an infinite level in PHP, although once you get beyond two levels, it can be very confusing for someone who is trying to read your code.
Continue Reading →

  • Archives

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