Tag Archive for code

Php Feedback Form w/ Session and Browser Info

<? include("browser_class.php"); ?> //include class from here <a href="http://snipplr.com/view/35627/php-browser-detection-class/" >http://snipplr.com/view/35627/php-browser-detection-class/</a>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "<a href="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">" >http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></a>
<html xmlns="<a href="http://www.w3.org/1999/xhtml">" >http://www.w3.org/1999/xhtml"></a>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" href="attSearch.css" type="text/css" />
<style>
body {width:400px;margin:0px auto;text-align:left!important}
h2 {color:green;}
</style>
</head>

<body style="background:none!important;">
<?php
// declare values
$loc = $_COOKIE['location'];
$contact_email = $_POST['EmailAddress'];
$contact_subject = $_POST['Subject'];
$contact_name = $_POST['FullName'];
$contact_message = $_POST['Message'];
$contact_custname = $_SESSION['businessName'];
$contact_accno = $_SESSION['accountNo'];
$mydate = date ( 'l, F d Y g:i A',time()+240 );
// where to send e-mail to
$to = '<a href="mailto:youremail@yourprovider.com">youremail@yourprovider.com</a>';

// e-mail subject
$subject = "Feedback from $contact_custname";

// e-mail message
$message = "You have received feedback:
"."----------------------------------------------
"
."Contact Name: $contact_name
"
."Business Name: $contact_accno, $contact_custname
"
."Subject: $contact_subject
"
."Submitted: $mydate
"
."From IP: {$_SERVER['REMOTE_ADDR']}
"
."URL: $loc
"
."Browser: $Browser->Name $Browser->Version
"
."Message: $contact_message";

$headers = "From: $contact_name <$contact_email>
"
."Reply-To: $contact_email
"
."X-Mailer: PHP/".phpversion();

// check for validation, then send the e-mail
if(empty($contact_name) || empty($contact_email) || empty($contact_subject) || empty($contact_message)) {
echo '<h2>Have feedback?</h2>
<form method="post" action="">
<table id="Form-Details">
<tbody>
<tr><td width="20%">Your Name:</td><td><input type="text" name="FullName" size="40" /></td></tr>
<tr><td width="20%">Subject:</td><td><select name="Subject">
		<option value="Feedback">Feedback</option>
		<option value="Suggestion">Suggestion</option>
		<option value="Bug Report">Bug Report</option>
		<option value="Question">Question</option>
		</select>
</td></tr>
<tr><td width="20%">Email:</td><td colspan="3"><input type="text" name="EmailAddress" size="40" /></td></tr>
<tr><td colspan="4">Message:</td></tr>
<tr><td colspan="4"><textarea rows="6" name="Message" cols="47" class="input"></textarea></td></tr>
<tr><td colspan="4" align="right"><input type="submit" value="Submit Feedback" /></td></tr>
</tbody>
</table>
</form>';
} elseif(!ereg("^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$", $contact_email)) {
echo "<h2 style='font-weight:bold;color:red;'>ERROR: Please enter a valid e-mail address.</h2>";
} else {
mail( $to, $subject, $message, $headers );
echo "<h2>Message Sent!</h2><br /><p>$contact_name,<br /><br />Thank you for your feedback, we will get back to you as soon as possible using $contact_email.";
}
?>
</body>
</html>

source

Block malicious URL Requests on WordPress

<?php
/*
Plugin Name: Block Bad Queries
Plugin URI: <a href="http://perishablepress.com/press/2009/12/22/protect-wordpress-against-malicious-url-requests/" >http://perishablepress.com/press/2009/12/22/protect-wordpress-against-malicious-url-requests/</a>
Description: Protect WordPress Against Malicious URL Requests
Author URI: <a href="http://perishablepress.com/" >http://perishablepress.com/</a>
Author: Perishable Press
Version: 1.0
*/
global $user_ID; if($user_ID) {
  if(!current_user_can('level_10')) {
    if (strlen($_SERVER['REQUEST_URI']) > 255 ||
      strpos($_SERVER['REQUEST_URI'], "eval(") ||
      strpos($_SERVER['REQUEST_URI'], "CONCAT") ||
      strpos($_SERVER['REQUEST_URI'], "UNION+SELECT") ||
      strpos($_SERVER['REQUEST_URI'], "base64")) {
        @header("HTTP/1.1 414 Request-URI Too Long");
	@header("Status: 414 Request-URI Too Long");
	@header("Connection: Close");
	@exit;
    }
  }
}
?>

source

Tag pre crossbrowser

pre {
   white-space: pre-wrap; /* css-3 */
   white-space: -moz-pre-wrap !important; /* Mozilla, since 1999 */
   white-space: -pre-wrap; /* Opera 4-6 */
   white-space: -o-pre-wrap; /* Opera 7 */
   word-wrap: break-word; /* Internet Explorer 5.5+ */
}

source

Howto list all the file extension types in an SVN log dump

svn log -v > myrepo.log

perl -ne 'print qq{$1
} if m{^s+.*(.[^.s]w+)$}' myrepo.log | sort | uniq -c | sort -r

source

latex source code formatting

	itle{Nice Code}
author{Jonathan Bunde-Pedersen}

documentclass[12pt]{article}

usepackage{color}
usepackage{fancyvrb}
usepackage{listings}

% include the lines below to use a nicer fixed-width font than the default one
usepackage{fontspec}
setmonofont[Scale=0.8]{Consolas} 

lstset{fancyvrb=true}
lstset{
	basicstyle=small	t,
	keywordstyle=color{blue},
	identifierstyle=,
	commentstyle=color{green},
	stringstyle=color{red},
	showstringspaces=false,
	tabsize=3,
	numbers=left,
	captionpos=b,
	numberstyle=	iny
	%stepnumber=4
	}

egin{document}
maketitle

section{Some nice Java code}

egin{figure}[h]
lstset{language=java,caption=Nicely formatted code.,label=lst:nicecode}
egin{lstlisting}
public class Whatever {
	public static void main(String[] args) {
		// whatever
		System.out.println("Hello, world!");
	}	
}
end{lstlisting}
end{figure}


end{document}

source

key code exceptions

var x = {
	'backspace' : 8,
	'tab' : 9,
	'enter' : 13,
	'shift' : 16,
	'ctrl' : 17,
	'alt' : 18,
	'pause' : 19,
	'caps lock' : 20,
	'escape' : 27,
	'page up' : 33,
	'page down' : 34,
	'end' : 35,
	'home' : 36,
	'left arrow' : 37,
	'up arrow' : 38,
	'right arrow' : 39,
	'down arrow' : 40,
	'insert' : 45,
	'delete' : 46,
	'left window key' : 91,
	'right window key' : 92,
	'select key' : 93,
	'numpad 0' : 96,
	'numpad 1' : 97,
	'numpad 2' : 98,
	'numpad 3' : 99,
	'numpad 4' : 100,
	'numpad 5' : 101,
	'numpad 6' : 102,
	'numpad 7' : 103,
	'numpad 8' : 104,
	'numpad 9' : 105,
	'multiply' : 106,
	'add' : 107,
	'subtract' : 109,
	'decimal point' : 110,
	'divide' : 111,
	'f1' : 112,
	'f2' : 113,
	'f3' : 114,
	'f4' : 115,
	'f5' : 116,
	'f6' : 117,
	'f7' : 118,
	'f8' : 119,
	'f9' : 120,
	'f10' : 121,
	'f11' : 122,
	'f12' : 123,
	'num lock' : 144,
	'scroll lock' : 145,
	'semi-colon' : 186,
	'equal sign' : 187,
	'comma' : 188,
	'dash' : 189,
	'period' : 190,
	'forward slash' : 191,
	'grave accent' : 192,
	'open bracket' : 219,
	'back slash' : 220,
	'close braket' : 221,
	'single quote' : 222
};

source

comment out HTML

<!-- ��� -->
Usage Recommendation
use it


<!-- ��� --> allows you to insert comments into an HTML document and have them completely ignored by the browser. This is useful for such things as revision histories and notes about how to improve the document.

For example, this code


<!-- Creation Date: June 21, 1996              -->
<!-- Modifications:                            -->
<!-- Sep 26, 1996: Added Links to Steve's Page -->
<!-- Oct 10, 1996: Updated product list        -->
produces this (nothing):

<!-- ��� --> will even "comment out" other tags. Everything is commented out until the closing -->. However, commenting out code tends to result in sloppy code. The best use for <!-- ��� --> in this sense is for experimentation, to try out different code without deleting other attempts. But when the experimentation is done, take out the unused code.

For example:


<!-- <IMG SRC="biguglypumpkin.gif" ALT="pumpkin"> -->
<IMG SRC="pumpkin.gif" ALT="pumpkin">
would be good for trying out different GIFs, but take out the commented part after you've decided on an image.

Comments may not have double hyphens (--) within them. This is because technically the comment ends with --, not -->. In practice virtually all browsers don't end the comment until -->.

source

Validate Canadian Postal Code

function fnValidatePostal($mValue, $sRegion = '')
{
$mValue = strtolower($mValue));
$sFirst = substr($mValue, 0, 1);
$sRegion = strtolower($sRegion);

$aRegion = array(
'nl' => 'a',
'ns' => 'b',
'pe' => 'c',
'nb' => 'e',
'qc' => array('g', 'h', 'j'),
'on' => array('k', 'l', 'm', 'n', 'p'),
'mb' => 'r',
'sk' => 's',
'ab' => 't',
'bc' => 'v',
'nt' => 'x',
'nu' => 'x',
'yt' => 'y'
);

if (preg_match('/[abceghjlkmnprstvxy]/', $sFirst) && !preg_match('/[dfioqu]/', $mValue) && preg_match('/^wdw[- ]?dwd$/', $mValue))
{
if (!empty($sRegion) && array_key_exists($sRegion, $aRegion))
{
if (is_array($aRegion[$sRegion]) && in_array($sFirst, $aRegion[$sRegion]))
{
return true;
}
else if (is_string($aRegion[$sRegion]) && $sFirst == $aRegion[$sRegion])
{
return true;
}
}
else if (empty($sRegion))
{
return true;
}
}

return false;
}

source

Postal code

public static class PostalLookup
{
public static Postal Find(string countryCode, string postalCode)
{

// remove letters from postal code
postalCode = Regex.Replace(postalCode, "[^0-9]", "");

if (string.IsNullOrEmpty(postalCode) || postalCode.Length != 4)
return null;

if (string.IsNullOrEmpty(countryCode))
return null;


// create the web request to the GeoNames interface
const string geoNamesUrl = "http://ws.geonames.org/postalCodeLookupJSON?postalcode={0}&country={1}";
WebRequest geoNamesRequest = WebRequest.Create(String.Format(geoNamesUrl, postalCode, countryCode));

// make the call
WebResponse geoNamesResponse = geoNamesRequest.GetResponse();

// grab the response stream
var geoNamesReader = new StreamReader(geoNamesResponse.GetResponseStream());

// put the whole response in a string
string geoNamesContent = geoNamesReader.ReadToEnd();

try
{

JObject o = JObject.Parse(geoNamesContent);
var postal = new Postal
{
Code = (string)o["postalcodes"][0]["postalcode"],
PlaceName = (string)o["postalcodes"][0]["placeName"],
County = (string)o["postalcodes"][0]["adminName1"]
};
return postal;
}
catch
{
return null;
}
}
}

public class Postal
{
public string Code { get; set; }
public string PlaceName { get; set; }
public string County { get; set; }
}

source

regex in Dreamweaver

The regular expression you seek is: [^"]*

so if you want to change all these:

<a class="wildcat" href="lion.html">
<a class="wildcat" href="tiger.html">
<a class="wildcat" href="leopard.html">

to:

<a class="wildcat" href="bigcat.html">

you search for:

<a class="wildcat" href="[^"]*">

and replace with:

<a class="wildcat" href="bigcat.html">

(make sure you tick the match case & regular expressions + seclect 'source code')

source