Category: PHP

In our PHP session you will learn about PHP, and how to execute scripts on your application

PHP Automatic Session Logout

Automatic logout script if users have inactive more than 15 minutes [php] <?php session_start(); $inactive = 900; // Set timeout period in seconds if (isset($_SESSION[‘timeout’])) { $session_life = time() – $_SESSION[‘timeout’]; if ($session_life > $inactive) { session_destroy(); header("Location: logoutpage.php"); } } $_SESSION[‘timeout’] = time(); ?> [/php]

Permanent link to this article: https://blog.openshell.in/2011/09/php-automatic-session-logout/

PHP MYSQL ORDER BY Multiple Columns

If you want to Order 2 or more columns in SQL Query. When ordering by more than one column, the second column is only used if the values are identical with the onces in the first column. Example [sql] ‘Order by Column ORDER BY COLUMN1, COLUMN2 [/sql] Order 2 or more columns with different orders …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/09/php-mysql-order-by-multiple-columns/

String Function in PHP

nl2br(): The nl2br() function adds the tag if it finds the carriage return (n) in the text. If you text is long and at many places carriage return is present, even then the nl2br() tag will replace all the occurrence of the carriage return with tag. Here is the syntax of the nl2br() tag: [php] …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/08/string-function-in-php/

String Functions in PHP [heredoc syntax]

The heredoc syntax: In addition of the single quote and double quote syntaxex, PHP provides another way to specify a string called heredoc syntax. This syntax turns out to be a extremely useful for specifiying large chunks of variable-interpolated text, because it spares you from the need to escape internal quotation marks. It is especially …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/08/string-functions-in-php-heredoc-syntax/

Read and Write an XML File using PHP

How to read and write xml document with php’s DOMDocument. The DOM extension allows you to operate on XML documents through the DOM API with PHP 5. For better understanding, I have written comment for almost every line of code. XML Code: file name – employee.xml [xml] <?xml version="1.0"?> <employees> <employee id="1" name="Albert"><age>34</age><![CDATA[ Employee details …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/07/read-and-write-an-xml-file-using-php/

Display first sentence with PHP

To display the first sentence of the paragraph with PHP. Use this code Code [php] function first_sentence($content) { $pos = strpos($content, ‘.’); if($pos === false) { return $content; } else { return substr($content, 0, $pos+1); } } [/php] Invoke the function like [php] echo first_sentence($content); [/php]

Permanent link to this article: https://blog.openshell.in/2011/07/display-first-sentence-with-php/

Window.open Not Working In IE

If you use window.open to open custom windows with JavaScript, you might encounter problems in Internet Explorer. Even though you can open new windows in other browsers, it doesn’t work in IE. The reason to this is it depends on how you name your JavaScript windows. IE doesn’t allow space here. window.open takes three parameters …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/07/window-open-not-working-in-ie/

Loading Javascript dynamically using jquery

If you are creating a web application, then your web pages may have all possibilities of being overwhelmed with a number of JavaScript files. Including large number of JavaScript files may slow down your web page. So its a good idea to load JavaScript dynamically to your web page, i.e load them only when these …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/06/loading-javascript-dynamically-using-jquery/

Create an RSS feed with PHP

Having an RSS feed on your website is a great way of sharing your content with the rest of the Internet. It’s not a new technology and it’s probably something that you use on a daily basis. If you have a blog or use any form of CMS, that software will most likely handle the …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/06/create-an-rss-feed-with-php/

Guide to MySQL database Engine.

A MySQL database gives you a choice of database engines and an easy way to switch them. Default MySQL Engine would be enough for most of your application but in certain circumstances where the other available engines may be better suited to the task at hand. Choose your engine The number of database engines available …

Continue reading

Permanent link to this article: https://blog.openshell.in/2011/06/guide-to-mysql-database-engine/