.MDS File Extension
Information file that describes the formatting of a CD or DVD; includes header information, which defines the tracks on the disc and the way the data is organized; recorded by disc imaging programs and recognized by standard CD and DVD players.
The MDS file is often found with a corresponding .ISO file or .MDF file, which contains the actual data from the disc. It is similar to a .CUE file, which describes the data stored in a .BIN file.
|
||||||||||||||||||||||||||||
Running php scripts using cron
Lots of programmers like PHP for its ability to code and develop web applications fast. Code-debugging is a lot easier than with PERL or C. However, there is one thing a lot of developers are puzzled about, “How to run PHP Scripts with crontab?”
Cron is normally available on all Unix and Linux distributions; if you cannot access it, contact your root or server administrator. It is a daemon which allows you to schedule a program or script for a specific time of execution. If you want to learn more about cron, click here or type “man crontab” at your command prompt.
I have found myself in the need to run PHP scripts at specific times. For example, to update the content of a website, to remove expired articles, to send out e-mails on a given date and a lot more. While some may think that this is were PHP is doomed, I will show you how it’s done.
A Manual crontab?
The first solution that came to my mind was to run the script directly from my browser (e.g. http://www.mydomain.com/script.php). Since I need to run my script on a regular basis, I squashed that idea. My goodness, all the extra hassle is ridiculous.
An include?
Another possible solution is to include the script in one of the pages of the site, for example the very first: “index.php”. (<? include “cron.php”; ?>)
The drawbacks to this solution are, that it works but when someone accesses the “index.php”. This could cause a lot of extra overhead produced by the script. If you get a lot of traffic, the script is executed 1000 times a day and adds a lot of usage on the database and the server.
On the other hand, if you do not get a lot of traffic, or people tend to access your site over another file, this will not work out as well. If you need to run the script on a regular intervals, this is not a solution.
Crontab!
Let’s suppose you either know what cron is or have read about it using the link above. We want to run our script once a minute. So where do we go from here? Here is how you can accomplish this task.
Your PHP setup
You will need to find out the answer to the following question, “Is my PHP installed as CGI or as an Apache module?”. To find out do the following: Create a new file, name it info.php (just an example), and put in the following code, “<? phpinfo(); ?>”. Upload to your webserver and go to it with your browser.
Now check for Server API (4th item from the top), if it says “CGI”, you have PHP compiled as CGI, if it reads “Apache”, you have it running as an Apache module.
Compiled CGI
If the answer to the question above is “CGI” then you need to add a line to your PHP script. It has to be the first line of your script and must contain your server’s PHP executable location:
#!/usr/local/bin/php -q
That looks a lot like PERL now, doesn’t it? After that let’s add the necessary command to our crontab. Edit /etc/crontab and add the following line:
* * * * * php /path/to/your/cron.php
Execute the following from the command line:
Shell> crontab crontab
Be sure your “script.php” has the necessary permissions to be executable (“chmod 755 script.php”).
Now you are all set!
Apache module
If your PHP is installed using the Apache module, the approach is a little different. First, you need access to Lynx (Lynx Browser for more information). Lynx is a small web browser, generally available on Unix and Linux.
Running your PHP script will not require you to add any additional lines. You simply have to edit your /etc/crontab file and add the following line:
* * * * * lynx -dump http://www.somedomain.com/cron.php
Please note that in general, you have to specify the entire URL (with “http://” and so on). But depending on your Lynx’s configuration, the URL might be relative; I suggest always using the absolute reference as in my example above – it always works.
Again execute the following from the command line:
Shell> crontab crontab
That all it takes to get a cron job setup using PHP. Hope you have learned something new and will use it to save overhead time on the server and on the developer.
Alexa ranking using php script
if you want to check the your website ranking as per alexa so you can use the following code in your php projects.
http://data.alexa.com/data?cli=10&dat=s&url=how2dev.com
“http://data.alexa.com/data” this file will return the xml format output. Using the XML output or reading xml file we can easily fetch the our or any website ranking.
Use the following function for getting the alexa website ranking.
<?php function AlexaRank( $url ) { preg_match( '#<POPULARITY URL="(.*?)" TEXT="([0-9]+){1,}"/>#si', file_get_contents('http://data.alexa.com/data?cli=10&dat=s&url=' . $url), $p ); return ( $p[2] ) ? number_format( intval($p[2]) ):0; } echo "wordpressapi.com Rank as per alexa.com: "; echo AlexaRank('how2dev.com'); ?> if you want to check the multiple website ranking in one shot than use the following PHP code. <?php $domains = array( 'google.com', 'ask.com', 'yahoo.com', 'bing.com' ); foreach ( $domains as $domain ) echo $domain, ' - ', AlexaRank( $domain ), '<br />', PHP_EOL; ?>
parentNode Property
Value: Node object reference or null
Compatibility: WinIE5+, MacIE5+, Moz1+, Safari1+
The parentNode property returns a reference to the next outermost node that is reflected as an object belonging to the document. For a standard element object, the parentNode property is the same as IE’s parentElement because both objects happen to have a direct parent-node relationship as well as a parent-child element relationship.
Other kinds of content , however can be nodes. This includes text fragments within an element. A text fragment’s parentNode property is the next outermost node or element that encompasses that fragment. A text node object in IE does not have a parentElement property.
Related Items: childNodes, nodeName, nodeType, nodeValue, parentElement properties.
parentElement property
Value: Element object reference or null
Compatibility: WinIE4+, MacIE4+, Moz-, Safari-
The parentElement property returns a reference to the next outermost HTML element from the current element. This parent-child relationship of elements is often, but not always, the same as parent-child node relationship. The difference is that the parentElement property deals only with HTML elements as reflected as document objects, whereas a node is not necessarily an HTML element (an attribute or text chunk).
There is also a distinction between parentElement and offsetParent properties. The latter returns an element that may be many generations removed from a given element but is the immediate parent with regard to positioning context. For example, a td element’s parentElement property is its enclosing tr element, but a td element’s offsetParent property is its table element.
Related Items: ossetParent, parentNode properties.
ownerDocument
Value: Document object reference
Compatibility: WinIE6+, MacIE5+, Moz1+, Safari1+
The ownerDocument property belongs to any element or node in the W3C DOM. The property’s value is a reference to the document node that ultimately contains the element or node. If a script encounters a reference to an element or node, the object’s ownerDocument property provides a way to build references to other objects in the same document or to access properties and methods of the document objects.
Example:
document.body.childNodes[5].ownerDocument
The result is a reference to the document object. You can use that to inspect a property of the document,
document.body.childNodes[5].ownerDocument.URL
This returns the document.URL property for the document that owns the child node.
Related Item: document object.
offsetParent
Value: Object reference
Compatibility: WinIE4+, MacIE4+, NN6+, Moz1+, Safari1+
The offsetParent property returns a reference to the object that acts as a positioning context for the current element.Values for the offsetLeft and offsetTop are measured relative to the top-left corner of the offsetParent object.
The returned object is usually , but not always the next outermost block-level container. For most document elements the offsetParent object is the document.body object.
The property behaves predictably for positioned elements in most browsers.
Code:
<html>
<head>
<title>offsetParent Property</title>
<script type="text/javascript">
function setImagePosition()
{
var x = 0;
var y = 0;
var offsetPointer = document.getElementById("myCell");
while(offsetPointer)
{
x += offsetPointer.offsetLeft;
y += offsetPointer.offsetTop;
offsetPointer = offsetPointer.offsetParent;
}
//correct for MacIE body margin factors
if(navigator.userAgent.indexOf("Mac") != -1 &&
typeof document.body.leftMargin != "undefined")
{
x += document.body.leftMargin;
y += document.body.topMargin;
}
document.getElementById("myDiv").style.left = x + "px";
document.getElementById("myDiv").style.top = y + "px";
document.getElementById("myDiv").style.visibility = "visible";
}
</script>
</head>
<body onLoad="setImagePosition()">
<h1>The offset property</h1>
<p>After the document loads, the script positions a small image in the upper
corner of the second table cell.</p>
<table border="1" align="center">
<tr>
<td>First cell</td>
<td id="myCell">Second cell</td>
</tr>
</table>
<img src="image.png" id="myDiv" height="12" width="12"
style="position:absolute;visibility:hidden;" />
</body>
</html>
Dynamic Navigation Menus
Next code demonstrates how to build a simple menu function with the current page high-lighted.
Code:
<?php require_once('menu.php'); $page = isset($_GET['page']) ? $_GET['page'] : 'home'; ?> <html> <head> <title>Page - <?=$page?> <style type="text/css"> .inactive, .active { padding:2px 2px 2px 20px; } .inactive { background:#ddd; } .active { background:black; font-weight:bold; } .inactive a { text-decoration:none; } .active a { text-decoration:none; color:white; } </style> </title> </head> <body> <table> <tr> <td width="200" valign="top"> <?php page_menu($page); ?> </td> <td width="600" valign="top"> Page: <?=$page?> </td> </tr> </table> </body> </html>
Save this code as index.php
<?php function menu_item($id, $title, $current) { $class = ($current == $id) ? "active" : "inactive"; ?> <tr><td class=<?=$class?>> <a href="index.php?page=<?=$id?>"><?=$title?></a> </td></tr> <?php } function page_menu($page) { ?> <table width="100%"> <?php menu_item('home', 'Home', $page); ?> <?php menu_item('about', 'About', $page); ?> <?php menu_item('browse', 'Browse', $page); ?> <?php menu_item('download', 'Download', $page); ?> </table> <?php } ?>
Save this code as menu.php
Drop-Down Stickies
Attaching a drop-down sticky to a word or phrase in your document is an easy way to add valuable information close to the word, without obscuring it.
Code:
<?php
function start_link($text, $nextid)
{
$idtext = $nextid;
?>
<a href="javascript:void drop('<?=$idtext?>');">
<span id="a_<?=$idtext?>"><?=$text?></span>
</a>
<div id="<?=$idtext?>" class="drop" style="display:none">
<table cellspacing="0" cellpadding="0" width="170">
<tr>
<td valign="top" width="20">
<a href="javascript:void close(<?=$idtext?>)">
<img src="close.gif" border="0" />
</a>
</td>
<td valign="top" width="150">
<?php
}
//--------------------
function end_link()
{
?>
</td>
</tr>
</table>
</div>
<?php
}
//-----------------
function link_header()
{
?>
<style type="text/css">
.drop
{
padding:5px;
font-size:small;
background:#eeeeee;
border:1px solid black;
position:absolute;
}
</style>
<script type="text/javascript">
function drop(sid)
{
aobj = document.getElementById("a_" + sid);
divobj = document.getElementById(sid);
divobj.style.top = (aobj.offsetBottom + 10) + "px";
divobj.style.left = (aobj.offsetLeft + 10) + "px";
divobj.style.display = "block";
}
function close(sid)
{
divobj = document.getElementById(sid);
divobj.style.display = "none";
}
</script>
<?php
}
?>
<html>
<head>
<?php link_header(); ?>
</head>
<body>
Hello <?php start_link("my friend", 1); ?>
Jimmy <?php end_link(); ?> .How are you?
</body> </html>
Save this code as drop-down.php
Section Content with Spinners
This code shows how to create sections on your page with spinners that open and show section of the content interactively.
Code:
<?php
function start_section($id, $title)
{
?>
<table cellspacing="0" cellpadding="0">
<tr>
<td width="30" valign="top">
<a href="javascript:void twist('<?=$id?>');">
<img src="up.gif" border="0" id="img-<?=$id?>" />
</a>
</td>
<td width="90%">
<h1><?=$title?></h1>
<div style="display:none;position:absolute" id="<?=$id?>" class="content">
<?php
}
function end_section()
{
?>
</div>
</td>
</tr>
</table>
<?php
}
?>
<html>
<head>
<style type="text/css">
body{font-family:Verdana;}
h1{font-size:medium;border-bottom:1px solid black;}
.content{font-size:small; margin-left:10px; padding:10px;}
</style>
<script type="text/javascript">
function twist(sid)
{
imgobj = document.getElementById("img-" + sid);
divobj = document.getElementById(sid);
if(imgobj.src.match("up.gif"))
{
imgobj.src = "down.gif";
divobj.style.position = "relative";
divobj.style.display = "block";
}
else
{
imgobj.src = "up.gif";
divobj.style.display = "none";
divobj.style.position = "absolute";
}
}
</script>
</head>
<body>
<?php start_section("first", "section one"); ?>
first part first part first part first part first part.
first part first part first part first part first part.
<?php end_section(); ?>
<?php start_section("sec", "section two"); ?>
section two section two section two section two section two.
section two section two section two section two section two.
<?php end_section(); ?>
</body>
</html>
Save the as spinners.php
