PHP: List Directories And Files On my server

May 13th, 2009

I found the easiest solution for listing directories and files on my server. Please take a look below:
<?
$dir = “images/”; //You could add a $_GET to change the directory
$files = scandir($dir);
foreach($files as $key => $value){
echo $value; //You could add an icon in here maybe, a link to the file/directory, or a link to list files [...]

Filled Under: PHP

PHP: the easiest way to inforce SSL

December 18th, 2008

How do I rewrite non-https to HTTPS? The easiest solution is by entering 2 simple lines into your .htaccess.

See below:

RewriteCond %{HTTPS} !=on
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

Filled Under: PHP

PHP: redirect visitors using .htaccess

December 18th, 2008

There are a lot of times when you want to redirect your users from page1 to page2.
You can simply do that by enring few lines into .htaccess. Here is an example.
Let’s say, you don’t want your visitors to see you working on the website. Instead you would like to show them a page telling that [...]

Filled Under: PHP

PHP: custom error pages with .htaccess

December 18th, 2008

I want to share this very simple trick which might help you to present errors in a user firendly pages.
Let’s say, user by accident types your page name incorrectly. Istead of showing typical “Page Cannot be Found” error, let’s do something quick but nice.

Open your .htaccess file (it’s ussually located on your root folder) and [...]

Filled Under: PHP

PHP send email

December 18th, 2008

Sending e-mail from php should be very easy. Here is how I do it:
<?php
//define the receiver of the email
$to = ‘youraddress@example.com’;
//define the subject of the email
$subject = ‘Test email’;
//define the message to be sent. Each line should be separated with \n
$message = “Hello World!\n\nThis is my first mail.”;
//define the headers we want passed. Note that they are separated with [...]

Filled Under: PHP