Dodona gives you answers

Archive for the ‘PHP’ Category

How do I truncate an HTML string without breaking the HTML code?

with 19 comments

Sometimes on a website, you just want to show the first few hundred characters of a text as an introduction, and link to the full text. But by simply using the PHP substr() function, you’re likely to break the HTML code or cut words in half. The PHP function below allows you to maintain your HTML and complete words while trimming your HTML string. The code is from the cakephp framework.

Links:
www.gsdesign.ro/blog/cut-html-string-without-breaking-the-tags
www.cakephp.org

Read the rest of this entry »

Advertisements

Written by lutsen

April 5, 2009 at 1:55 pm

Posted in PHP

Where can I test different Content Management Systems?

leave a comment »

If you’re looking for an open source LAMP (Linux Apache MySQL PHP) based CMS, but you want to test some first, try opensourcecms.com. They provide working demo’s of just about every open source LAMP content management system.

Link: www.opensourcecms.com

Written by lutsen

October 14, 2008 at 2:23 pm

Posted in PHP, Web

What is an easy way to get all the data from my MySQL database?

leave a comment »

I recently just wanted to get all the data from a MySQL database, without having to install phpMyAdmin or something similar extended. This nice script did the job.

Link: quirm.net/2008/10/02/mysql-backup/

Status: Tested it, works, like it

To view the code press: Read the rest of this entry »

Written by lutsen

September 13, 2008 at 9:35 am

Posted in PHP

What is a good, secure, developer friendly and user friendly PHP login script?

I wrote one myself, it’s called P.U.L.S. and you can download it and read all about it on dodona.wordpress.com/puls. P.U.L.S means PHP User Login Script and is a PHP scritp which enables users to register and then login to a website or -page.

Read more >

Written by lutsen

September 9, 2008 at 1:02 pm

Posted in PHP

How can I check if PHP on my webserver supports sessions?

leave a comment »

The simplest way to check if sessions are enabled on your PHP installation is with the phpinfo(); command:

<?php phpinfo(); ?>

This generates a table with an overview of all PHP settings on your server.

To check if sessions really work you can use this code:

<?php
// Start Session
session_start();
// Show banner
echo '<b>Session Support Checker</b><hr />';
// Check if the page has been reloaded
if(!isset($_GET['reload']) OR $_GET['reload'] != 'true') {
   // Set the message
   $_SESSION['MESSAGE'] = 'Session support enabled!<br />';
   // Give user link to check
   echo '<a href="?reload=true">Click HERE</a> to check for PHP Session Support.<br />';
} else {
   // Check if the message has been carried on in the reload
   if(isset($_SESSION['MESSAGE'])) {
      echo $_SESSION['MESSAGE'];
   } else {
      echo 'Sorry, it appears session support is not enabled, or you PHP version is to old. <a href="?reload=false">Click HERE</a> to go back.<br />';
   }
}
?>

Written by lutsen

August 26, 2008 at 2:21 pm

Posted in PHP, Web

How can I remove a directory from my webserver?

leave a comment »

The most obvious way would be to use an FTP client. But sometimes I run into the problem that directories, created with for example a CMS system that runs on the server, have another owner (namely the script that created them). That way it may happen that my FTP client doesn’t have enough rights to remove the directory. If this happens after I deleted the server-side script that created the directory, I am stuck with a directory I can’t get rid of.

This is where the PHP code below comes in handy. It removes a directory and its contents from the server. Because in situations as described above it usually has the same rights as the script that created te directory, it is likely to succeed where your FTP client might fail.

NOTE: be careful not to leave the script on your server after you have used it for obvious reasons…


<?php
function removeDir($path) {
   // Add trailing slash to $path if one is not there
   if (substr($path, -1, 1) != "/") {
      $path .= "/";
   }
   $normal_files = glob($path . "*");
   $hidden_files = glob($path . "\.?*");
   $all_files = array_merge($normal_files, $hidden_files);
   foreach ($all_files as $file) {
      // Skip pseudo links to current and parent dirs (./ and ../).
      if (preg_match("/(\.|\.\.)$/", $file)) continue;
      if (is_file($file) === TRUE) {
         // Remove each file in this Directory
         unlink($file);
         echo "Removed File: " . $file . "<br>";
      } else if (is_dir($file) === TRUE) {
         // If this Directory contains a Subdirectory, run this Function on it
         removeDir($file);
      }
   }
   // Remove Directory once Files have been removed (If Exists)
   if (is_dir($path) === TRUE) {
      rmdir($path);
      echo "<br>Removed Directory: " . $path . "<br><br>";
   }
}
// To remove a dir:
removeDir('/absolute/path/to/directory/to/remove');
?>

Written by lutsen

August 26, 2008 at 1:44 pm

Posted in PHP, Web