WebMe
homeaboutportfolioservicescontact

WebMe - Website Design & Development

previous posts
archives
 

All resources published on this blog are free to use and redistribute. All we ask is that you keep any copyright notices and links to WebMe in your code. If you find something really useful we would appreciate you placing a link on your site to ours.

 
uk web design association Valid XHTML 1.0 Transitional
Independent Web Developers Portal Valid CSS!

All major credit cards accepted

 

Web Site DesignSubscribe to this Blog

Get Current Directory Function in PHP

Something that many people ask for is an extremely simple piece of code and that is "How do I get the current directory in PHP?" Well, we use a function to do this and the code is as follows:
function getDirectory() {
 $f = getcwd();
 return substr($f, strrpos($f, "/") + 1);
}
The PHP function getcwd() returns the current working directory and path. The following line simply strips the path and returns the name of the current directory. Instead of using getcwd() you can also use dirname(__FILE__) so the code could be rewritten as:
function getDirectory() {
 $f = dirname(__FILE__);
 return substr($f, strrpos($f, "/") + 1);
}

Labels: ,

Design web site media
0 Comments

 

Web Site DesignSubscribe to this Blog

XML Sitemap Generator Script in PHP for Google and others

We develop a lot of websites and quite rightly the owners want their site to appear in Google as quickly as possible. One way to speed up this process is to use Google's sitemap tool.
Google accept sitemaps in various formats, one of them being XML.
Now if you have a site, or develop websites, that quite often have new content and pages being added to them it can be a pain to create a new sitemap each time. For this reason we have taken a nice little script developed in ASP by Francesco Passantino and rewritten it in PHP.
To use this script, simply place it in the root of your website and tell Google where it is in the Add Sitemap section of Google sitemaps.
The script will generate a valid XML sitemap that will dynamically update whenever new pages are added or pages are deleted.

Version 1.0 can be found here. This is for PHP5 only, we also have a PHP4 version which can be found here. To use the PHP4 version you will need the strripos PHP4 script from here.

Labels: , , , ,

Design web site media
3 Comments

 

Web Site DesignSubscribe to this Blog

Random Password Generator in PHP

Today we thought we'd share our random PHP password generator code with you. This function returns a variable length password comprised of upper and lower case characters with numbers. Simply pass the desired password length to the function.
function RandomPW($myLength) {
 //These constant are the minimum and maximum length for random
 //length passwords.  Adjust these values to your needs.
 $minLength = 6;
 $maxLength = 20;
 
 if ($myLength == 0) {
  $myLength = rand($minLength, $maxLength);
 }

 for ($X=1;$X<=$myLength;$X++) {
  //Randomize the type of this character
  $Y = rand(1,3); //(1) Numeric, (2) Uppercase, (3) Lowercase
  switch ($Y) {
   case 1:
    //Numeric character
    $strPW = $strPW.chr(rand(48, 57));
    break;
   case 2:
    //Uppercase character
    $strPW = $strPW.chr(rand(65, 90));
    break;
   case 3:
    //Lowercase character
    $strPW = $strPW.chr(rand(97, 122));
    break;
  }
 }
 return($strPW);
}

Labels: , ,

Design web site media
0 Comments

 

0870 2244850
info@webme.co.uk

copyright About UsServicesPortfolioDemoGet QuoteContact