Posts tagged ‘PHP’

March 6th, 2012

Create an Apache Sub-Domain

Not long ago, I was looking information on how to create and configure an Apache sub-domain on my test server.  I found a number of websites covering the subject, but even after editing my httpd.conf file to add the domain and sub-domain entries, the sub-domain would not work!?  So I did more digging and testing and what I found was that the various tutorials and explanations all omitted one crucial element to the puzzle, none of them mentioned that you had to also add a subdomain entry to Windows’ host file! I assumed that since the domain already had an entry, Apache & Windows were smart enough to know that a sub-domain would use the same host entry as the domain, I was wrong! Apparently, Apache & Windows are not that smart, actually they appear to be blatantly stupid!

So the first thing you have to do is edit the httpd.conf file to add the required virtual host entries: 1 for the domain & 1 for the sub-domain

<VirtualHost *:80>
    ServerName www.domain.com
    DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/websites/www.domain.com"
</VirtualHost>
<VirtualHost *:80>
    ServerName subdomain.domain.com
    DocumentRoot "C:/Program Files/Apache Software Foundation/Apache2.2/htdocs/websites/www.domain.com/subdomainFolderName"
</VirtualHost>

But even once this is done, you then have to go and make an entry for both your domain and another for your sub-domain in the Windows Host file.  The values below assume a local test server

127.0.0.1    www.domain.com
127.0.0.1    subdomain.domain.com

Once you make both of these changes, restart your Apache server, and everything should work.  It did for me at least!

Share and Enjoy

  • Google Plus
  • Facebook
  • LinkedIn
  • Twitter
  • Email
  • Print
June 6th, 2010

PHP Random String Generator

Have you ever need to generate a random string or generate a unique id using PHP. Below is a complete example of how to do so. Simply copy the entire code into a new php page and then open it.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PHP Random String Generator</title>
</head>
<body>
<?php
# AUTHOR: 		Daniel Pineault, CARDA Consultants Inc.
# DATE:			2010-06-25
# PURPOSE: 		Generate a random string or unique Id
# COPYRIGHT: 	You are free to use this code as you wish as long as
#	 			this header is include in the final work.  This is 
#				provided 'AS IS' and I assume no liability for its
#				usage.
#			

	foreach($_POST as $key=>$value) {
		$$key = strip_tags($value); //sanitize provided user entries
	}
 
	if(isset($GenRndStr)){
		$sUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
		$sLower = "abcdefghijklmnopqrstuvwxyz";
		$sNumbers = "0123456789";
		$sSpecial = "!@#$%^&*()[]{},.;:'/\~-+=|<>";
 
		if($UCase==1){
			$s .= $sUpper;
		}
		if($LCase==1){
			$s .= $sLower;
		}
		if($Nbr==1){
			$s .= $sNumbers;
		}
		if($SpecChrs==1){
			$s .= $sSpecial;
		}
		if(strlen($ExChrs)>0){
			for($k = 0; $k <= (strlen($ExChrs)-1); $k++){
				$s = str_replace($ExChrs{$k}, "", $s);
			}
		}
 
		$sLen = $RandStrLen;
 
		for($i = 1; $i <= $sLen; $i++){
			$sRandString .= $s{rand(1,strlen($s))};
		}
	}
?>
<h1>PHP Random String Generator</h1>
<form id="RndStrGen" name="RndStrGen" method="post">
<table border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td valign="top"><strong>Password Characteristics</strong> </td>
    <td><input type="checkbox" id="UCase" name="UCase" value="1"<?php
			 if ($UCase == 1) {
			 	echo ' checked="checked"';
			 }
			 ?> />
      Upper Case Characters<br />
      <input type="checkbox" id="LCase" name="LCase" value="1"<?php
			 if ($LCase == 1) {
			 	echo ' checked="checked"';
			 }
			 ?> />
      Lower Case Characters<br />
      <input type="checkbox" id="Nbr" name="Nbr" value="1"<?php
			 if ($Nbr == 1) {
			 	echo ' checked="checked"';
			 }
			 ?> />
      Numbers<br />
      <input type="checkbox" id="SpecChrs" name="SpecChrs" value="1"<?php
			 if ($SpecChrs == 1) {
			 	echo ' checked="checked"';
			 }
			 ?> />
      Special Characters (!@#$%^&*()[]{},.;:'/\~-+=|<>)</td>
  </tr>
  <tr>
    <td valign="top"><strong>Characters to Exclude</strong></td>
    <td><input type="text" id="ExChrs" name="ExChrs" value="<?= $ExChrs ?>" /></td>
  </tr>
  <tr>
    <td><strong>Password Length</strong> </td>
    <td><input type="text" id="RandStrLen" name="RandStrLen" value="<?= $RandStrLen ?>" /></td>
  </tr>
</table>
<p>
  <input type="submit" id="GenRndStr" name="GenRndStr" value="Generate String" />
</p>
</form>
<?php
	if(isset($sRandString)){
		echo "<p>".$sRandString."</p>\n";
	}
?>
</body>
</html>

Share and Enjoy

  • Google Plus
  • Facebook
  • LinkedIn
  • Twitter
  • Email
  • Print