Archive for April, 2010

IE7 php force download FIX

Friday, April 30th, 2010

Normally, as an  accomplished programmer, you use all the headers, follow the guidelines, include what you should…

but, when Microsoft won’t play by the rules, you have to fudge…

IE7 rejects forced downloads (in this example I was using doing PDF, mp3, zip, and m4b files).

It opens the download dialog, chooses a location, and then commences to quit having downloaded 0 bits.

So, instead of the dutiful example elsewhere in this blog that chooses the correct content-type, length, transer encoding and so on…

We just do this, seems to work, forces it somehow, sorry, I’ve no further explanation…:

<?

$filename = $_GET[‘file’];
// required for IE, otherwise Content-disposition is ignored
if(ini_get(‘zlib.output_compression’))
ini_set(‘zlib.output_compression’, ‘Off’);

$file_extension = strtolower(substr(strrchr($filename,”.”),1));
if( $filename == “” )
{
echo “<html><title></title><body>ERROR: download file NOT SPECIFIED.</body></html>”;
exit;
}

header(“Cache-Control: maxage=1”);
header(“Content-Type: application/force-download”);
header(“Content-disposition: attachment; filename=\””. $filename .”\”;” );
@readfile(“$filename”) or die(“File not found.”);
exit();

?>

htaccess file to restrict Godaddy

Friday, April 30th, 2010

I’m using this to lock a directory of assets for a client on a godaddy hosting plan:

order deny,allow
allow from localhost
deny from all

and then accessing files there from with a php file that checks their Zend logged in/file permissions etc.
(search this blog for “file serve” in content to find the php script)

AWESOME!

PHP htaccess file serve script

Friday, April 30th, 2010

search this blog for the “htaccess” file contents to put in a directory, then use this to serve up pdf files securely from said directory:

file serve php script:

first check Zend permissions…logged in, permissions granted, user active, expirations, etc…..
then:

<?
$file = “path/path/” . $_GET[‘file’];
//$file = “Broker_Admin/Materials/Course.pdf”;
header(‘Content-type: application/pdf’);
header(“Content-Disposition: inline; filename=”.$file);
/*header(“Content-Disposition: attachment; filename=”.$file);*/
header(‘Last-Modified: ‘.gmdate(‘D, d M Y H:i:s’) . ‘ GMT’);
header(‘Cache-Control: no-store, no-cache, must-revalidate’);
header(‘Cache-Control: pre-check=0, post-check=0, max-age=0’);
header(‘Pragma: anytextexeptno-cache’, true);
header(‘Cache-control: private’);
header(‘Expires: 0’);
readfile($file);
?>

then from wherever I want to call it I call this script and pass in the file wanted.

like this:

<a href=”file_serve.php?file=Test.pdf”>Download the Test file here</a>

File is NOT accessible directly, or via this script since it first checks visitor’s SESSIONS, ZEND Permissions, that variables passed to it are set, etc. and so on…

jQuery bind select change to anchor window.open variable

Thursday, April 29th, 2010

add window.open() to an anchor tag…

HTML:

select dropdown changes the source:

<div class=”name”>
<select name=”tpom” style=”float: left; width: 100px; margin-right:20px; border: 1px solid #5A3C18;” >
<option value=”downloader.php?file=folder/file.mp3″>Mp3</option>
<option value=”downloader.php?file=folder/file.zip”>Zip</option>
<option value=”downloader.php?file=folder/file.m4b”>Ipod</option>
</select>

link or button gets source from dropdown via jQuery onReady function:

$(“div.name select”).bind(“change”,function(){
$(‘#button_download’).attr(‘href’,this.value);
windowUrl = $(this).val();
//console.log(windowUrl);
});

<a onclick=”window.open(windowUrl,’download’);return false;” id=”button_download”>Download</a>

log to the console in firefox firebug javascript

Thursday, April 29th, 2010

console.log(windowUrl);

but remove it once you’ve learned what you need to as it will break things in other browsers…

session_start() php when to do it again!

Thursday, April 29th, 2010

I was stuck for a bit there.

I have a page that loads via AJAX, but I had to modify it to work for Google’s googlebot #! system…

The googlebot logic senses that it’s googlebot, and uses PHP includes instead of the AJAX!

Well the includes don’t need the session_start() again, but the AJAX loads DO!

So, NOT to be forgotten, session_start() will work per LOAD, hard to explain that, but you can wrap your head around it…

fancy!

BETTER SOLUTION: Sessions manager class, framework or similar…

fancy complex php force file download script

Thursday, April 29th, 2010

set_time_limit(0);
$file_path=’blah.pptx’;
output_file($file_path, ‘blah.pptx’, ”);

function dl_file($file){

$file = ‘blah.pptx’;
$filename = realpath($file);
$file_extension = strtolower(substr(strrchr($filename,”.”),1));

if (!file_exists($filename)) { die(“NO FILE HERE”); }
$ctype=”application/vnd.ms-powerpoint”;
header(“Pragma: public”);
header(“Expires: 0”);
header(“Cache-Control: must-revalidate, post-check=0, pre-check=0”);
header(“Cache-Control: private”, false);
header(“Content-Type: $ctype”);
header(“Content-Disposition: attachment; filename=\”$filename\””);
header(“Content-Transfer-Encoding: binary”);
header(“Content-Length: “.@filesize($filename));
set_time_limit(0);
@readfile($file);
exit;
}

function output_file($file, $name, $mime_type=”)
{

if(!is_readable($file)) die(‘File not found or inaccessible!’);

$size = filesize($file);
$name = rawurldecode($name);

/* Figure out the MIME type (if not specified) */
$known_mime_types=array(
“pdf” => “application/pdf”,
“txt” => “text/plain”,
“html” => “text/html”,
“htm” => “text/html”,
“exe” => “application/octet-stream”,
“zip” => “application/zip”,
“doc” => “application/msword”,
“xls” => “application/vnd.ms-excel”,
“ppt” => “application/vnd.ms-powerpoint”,
“gif” => “image/gif”,
“png” => “image/png”,
“jpeg”=> “image/jpg”,
“jpg” =>  “image/jpg”,
“php” => “text/plain”
);

if($mime_type==”){
$file_extension = strtolower(substr(strrchr($file,”.”),1));
if(array_key_exists($file_extension, $known_mime_types)){
$mime_type=$known_mime_types[$file_extension];
} else {
$mime_type=”application/force-download”;
};
};

@ob_end_clean(); //turn off output buffering to decrease cpu usage

// required for IE, otherwise Content-Disposition may be ignored
if(ini_get(‘zlib.output_compression’))
ini_set(‘zlib.output_compression’, ‘Off’);

header(‘Content-Type: ‘ . $mime_type);
header(‘Content-Disposition: attachment; filename=”‘.$name.'”‘);
header(“Content-Transfer-Encoding: binary”);
header(‘Accept-Ranges: bytes’);

/* The three lines below basically make the
download non-cacheable */
header(“Cache-control: private”);
header(‘Pragma: private’);
header(“Expires: Mon, 26 Jul 1997 05:00:00 GMT”);

// multipart-download and download resuming support
if(isset($_SERVER[‘HTTP_RANGE’]))
{
list($a, $range) = explode(“=”,$_SERVER[‘HTTP_RANGE’],2);
list($range) = explode(“,”,$range,2);
list($range, $range_end) = explode(“-“, $range);
$range=intval($range);
if(!$range_end) {
$range_end=$size-1;
} else {
$range_end=intval($range_end);
}

$new_length = $range_end-$range+1;
header(“HTTP/1.1 206 Partial Content”);
header(“Content-Length: $new_length”);
header(“Content-Range: bytes $range-$range_end/$size”);
} else {
$new_length=$size;
header(“Content-Length: “.$size);
}

/* output the file itself */
$chunksize = 1*(1024*1024); //you may want to change this
$bytes_send = 0;
if ($file = fopen($file, ‘r’))
{
if(isset($_SERVER[‘HTTP_RANGE’]))
fseek($file, $range);

while(!feof($file) &&
(!connection_aborted()) &&
($bytes_send<$new_length)
)
{
$buffer = fread($file, $chunksize);
print($buffer); //echo($buffer); // is also possible
flush();
$bytes_send += strlen($buffer);
}
fclose($file);
} else die(‘Error – can not open file.’);

die();
}

basic php force file download script

Thursday, April 29th, 2010

<?php
$filename = $_GET[‘file’];
// required for IE, otherwise Content-disposition is ignored
if(ini_get(‘zlib.output_compression’))
ini_set(‘zlib.output_compression’, ‘Off’);

$file_extension = strtolower(substr(strrchr($filename,”.”),1));
if( $filename == “” )
{
echo “<html><title></title><body>ERROR: download file NOT SPECIFIED.</body></html>”;
exit;
}
switch( $file_extension )
{
case “pdf”: $ctype=”application/pdf”; break;
case “txt”: $ctype=”text/plain”; break;
case “html”: $ctype=”text/html”; break;
case “htm”: $ctype=”text/html”; break;
case “exe”: $ctype=”application/octet-stream”; break;
case “zip”: $ctype=”application/zip”; break;
case “doc”: $ctype=”application/msword”; break;
case “xls”: $ctype=”application/vnd.ms-excel”; break;
case “ppt”: $ctype=”application/vnd.ms-powerpoint”; break;
case “gif”: $ctype=”image/gif”; break;
case “png”: $ctype=”image/png”; break;
case “jpeg”: $ctype=”image/jpg”; break;
case “jpg”: $ctype=”image/jpg”; break;
case “php”: $ctype=”text/plain”; break;
default: $ctype=”application/force-download”;
}
header(“Pragma: public”); // required
header(“Expires: 0”);
header(“Cache-Control: must-revalidate, post-check=0, pre-check=0”);
header(“Cache-Control: private”,false); // required for certain browsers
header(“Content-Type: $ctype”);
header(“Content-Disposition: attachment; filename=\””.basename($filename).”\”;” );
header(“Content-Transfer-Encoding: binary”);
header(“Content-Length: “.filesize($filename));
set_time_limit(0);
@readfile(“$filename”) or die(“File not found.”);
exit();
?>

meta no archive tag

Wednesday, April 28th, 2010

<META content=”noarchive” NAME=”robots”>

jQuery scrollTo id

Monday, April 26th, 2010

<style>

.pointer { cursor: pointer; }

</style>

<a class=”pointer” onclick=”$.scrollTo(‘#here1’, 1000); return false;”>Here</a>

<h3 id=”here1″>text</h3>

<h3 id=”here2″>text</h3>

MySQL phpMyAdmin text string find replace Query

Sunday, April 25th, 2010

update TABLE_NAME set FIELD_NAME =
replace(FIELD_NAME,’find this string’,’replace it with this one’);

example (for videodb to turn all “wanted” titles into “DVD” titles):

update videodb_videodata set mediatype =
replace(mediatype,’50’,’1’);

jQuery Javascript CSS gray out faded disabled element fadeTo() onload .ready()

Friday, April 23rd, 2010

Simply fade the element you’d like faded, grayed, via your .ready onload jQuery function:

$(document).ready(function() {

jQuery(‘#top_button’).fadeTo(0, 0.5);

});

jQuery set tag element disabled

Friday, April 23rd, 2010

jQuery(‘#element1’).attr(‘disabled’,’disabled’);

jQuery setTimeout fadeOut() fadeIn() show() hide() example

Friday, April 23rd, 2010

This is a bit of craziness, still it works nicely to hide a element, show another, and then a bit later hide the latter, and again show the original.

$(‘#item1’).bind(‘click’,function() {

$(‘#item1’).fadeOut( function(){

setTimeout( function(){

$(‘#item2’).fadeIn(function() {

setTimeout( function(){

$(‘#item2’).fadeOut(function(){

setTimeout( function() {

$(‘#item1’).fadeIn();

}, 100);

});

}, 2000 );

});

}, 100);

}); return false;

});

HTML form field readonly and disable

Thursday, April 22nd, 2010

<input type=”text” readonly=”readonly” …. />

and equally useful

<input type=”text” disabled=’disabled’ …/>

Platform Environments Config for PHP applications example $_SERVER[‘HTTP_HOST’]

Wednesday, April 21st, 2010

You have to look at all of your different server returned variables for each platform,

and simply find one that you may reference and set per platform via script similar to:

// PLATFORM CONFIG


if($_SERVER[‘HTTP_HOST’] == ‘localhost’)
{
define(‘HOME’,’http://localhost/url.com/’);
define(‘PLATFORM_DB’,’localhost’);
}
elseif($_SERVER[‘HTTP_HOST’] == ‘www-staging.url.com’)
{
define(‘HOME’,’http://www-staging.soundstrue.com/’);
define(‘PLATFORM_DB’,’mktgdb.url.com’);
}
elseif($_SERVER[‘HTTP_HOST’] == ‘www.url.com’);
{
define(‘HOME’,’http://www.url.com/’);
define(‘PLATFORM_DB’,’mktgdb.url.com’);
}

Then simply access the variable when needed:

header(“Location:” . HOME . “event/forums/site/index.php/”);

$boarddir = HOME . “event/forums/dangerous/index.php/board,1.0.html”;

This way you can develop on your local machine, promote your app to staging, where it will still work, and finally to production, all without re-coding those pesky app variables.

Loop through PHP $_SERVER variables / values

Wednesday, April 21st, 2010

<?PHP

foreach($_SERVER as $key_name => $key_value) {
print $key_name . ” = ” . $key_value . “<br>”;
}

?>

PHP MySQL date & time reference

Wednesday, April 21st, 2010

http://www.eltcalendar.com/stuff/datemysqlphp.html

thank you for this great handy reference!

pasted verbatim:

Format PHP MySQL
Time The function is:
date(format)
where “format” consists of the letters given below.
The functions are:
date_format(string, format)
time_format(string, format)
where “format” consists of the letters given below.)
hour, 2-digit, 12-hour (01-12) h %h
hour, 2-digit, 24-hour (00-23) H %H
hour, numeric, 12-hour (1-12) g %l
hour, numeric, 24-hour (0-23) G %k
minute, 2-digit (00-59) i %i
seconds, 2-digit (00-59) s %S
time, 24-hour (hh:mm:ss) none, use date(“H:i:s”) %T
time, 12-hour (hh:mm:ss AM/PM) none, use date(“g:i:s A”) %r
AM / PM (uppercase letters) A %p
am / pm (lowercase letters) a none
Days
day name, full (Sunday) l (a lowercase L) %W
day name, abbreviation (Sun) D %a
day as number of week (0-6) none, use a getdate() array:
First do this:
$dateInfo = getdate();
Your day as number of the week is $dateInfo[wday];
%w
day number of the year z
(Note: 0-365; ex: January 1st is 0)
%j
(Note: 001-366; ex: January 1st is 001)
Dates
month name in full (January) F %M
month name, abbreviated (Jan) M %b
month, 2-digit (01-12) m %m
month, no leading 0 (1, 2, 3 – 12) n %c
day of month, 2-digit (01, 02, …) d %d
day of month, no leading 0 (1, 2) j %e
day of month with ordinal suffix (1st, 2nd, 3rd, 4th…) none. Use jS %D
ordinal suffix (st, nd, rd, th) S none; use %D (above)
year, 4 digit (2001) Y %Y
year, 2 digit (00-99) y %y
Examples: To write: Use this: Use this:
Sunday, June 03, 2001 date(‘l, F d, Y’) date_format(date, ‘%W, %M %d, %Y’)
Sun., Jun 3rd, 2001. 11:30 AM date(‘D., M jS, Y.g:i A’) date_format(datetime, ‘%a., %b %D, %Y. %l: %i %p’)
Or if there are two columns, one date and one time, you’d use:
date_format(date, ‘%a., %b %D, %Y.’)
time_format(time, ‘%l: %i %p’)
See the note below)
2001-06-03 date(‘Y-m-d’) (see important note below; this is default for date-type columns so you don’t have to use any special function or formatting at all.)

Important Note:

The choice in MySQL between date_format() and time_format() depends on the type of column you have stored your date in.

MySQL column type: Data format in the column (all parts are required) Example: Use:
date YYYY-MM-DD 2001-06-03 date_format() to get date values
time (see “NB” below) hh:mm:ss 13:30:00 time_format() to get time values
datetime YYY-MM-DD hh:mm:ss 2001-06-03 13:30:00 date_format() to get date and/or time values

NB: the time type for MySQL columns actually represents an amount of time elapsed; thus, it can be negative or positive. However, it can also be used to represent the time of day, where it represents the amount of time elapsed since 1 second past midnight. If you forget to add :00 for seconds (for example, using 13:30 for 1:30 p.m.), your time value will be interpreted as the number of minutes and seconds after midnight, or 12:30 a.m. plus 30 seconds.

Firefox password manager asking and asking… turn it off

Monday, April 19th, 2010

options menu

“Security” tab

uncheck “Remember passwords for sites”

http://robert.accettura.com/blog/2007/05/07/disable-password-manager/

jQuery Fancybox IE width issue don’t forget the doctype!

Wednesday, April 14th, 2010

Required, a doctype!

example:

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN”
“http://www.w3.org/TR/html4/strict.dtd”>

also, it never hurts to go get the latest versions of jquery and fancybox, at the time of this post: http://code.jquery.com/jquery-1.4.2.min.js & fancybox-1.3.1.js worked nicely…

Lightwindow IE fix

Tuesday, April 13th, 2010

Replace:

this.checkImage = new PeriodicalExecuter(function(i) {
if (!(typeof $(‘lightwindow_image_’+i).naturalWidth != “undefined” && $(‘lightwindow_image_’+i).naturalWidth == 0)) {

this.checkImage.stop();

var imageHeight = $(‘lightwindow_image_’+i).getHeight();
if (imageHeight > this.resizeTo.height) {
this.resizeTo.height = imageHeight;
}
this.resizeTo.width += $(‘lightwindow_image_’+i).getWidth();
this.imageCount–;

$(‘lightwindow_image_’+i).setStyle({
height: ‘100%’, width: ‘100%’
});

if (this.imageCount == 0) {
this._processWindow();
}
}

}.bind(this, i), 1);

With:

// We have to do this instead of .onload
var ie = (document.all)?1:0;
this.checkImage = new PeriodicalExecuter(function(i) {
if(ie){ //THE BROWSER IS IE
if ( $(‘lightwindow_image_’+i).complete && !(typeof $(‘lightwindow_image_’+i).naturalWidth != “undefined” && $(‘lightwindow_image_’+i).naturalWidth == 0)) {
this.checkImage.stop();

var imageHeight = $(‘lightwindow_image_’+i).getHeight();
if (imageHeight > this.resizeTo.height) {
this.resizeTo.height = imageHeight;
}
this.resizeTo.width += $(‘lightwindow_image_’+i).getWidth();
this.imageCount–;

$(‘lightwindow_image_’+i).setStyle({
height: ‘100%’, width: ‘100%’
});

if (this.imageCount == 0) {
this._processWindow();
}
//alert(‘IE has been detected’)
}
}
else
{//NOT IE, PROBABLY FF, OPERA, OTHER
//this line works for all other browsers
if ($(‘lightwindow_image_’+i).complete && !(typeof $(‘lightwindow_image_’+i).naturalWidth != “undefined” && $(‘lightwindow_image_’+i).naturalWidth == 0)) {

this.checkImage.stop();

var imageHeight = $(‘lightwindow_image_’+i).getHeight();
if (imageHeight > this.resizeTo.height) {
this.resizeTo.height = imageHeight;
}
this.resizeTo.width += $(‘lightwindow_image_’+i).getWidth();
this.imageCount–;

$(‘lightwindow_image_’+i).setStyle({
height: ‘100%’, width: ‘100%’
});

if (this.imageCount == 0) {
this._processWindow();
}
}
}

}.bind(this, i), 1);

credit:
http://www.silverstripe.org/all-other-modules/show/251991?start=8

MySQL phpMyAdmin Query change table names syntax

Tuesday, April 13th, 2010

RENAME TABLE

database_name.table_name TO database_name.new_table_name,

database_name.table2_name TO database_name.new_table2_name;

NOTE the comma and the semicolon!

Prototype script.aculo.us form simple handling

Tuesday, April 13th, 2010

I’ve pretty much left script.aculo.us for jQuery for the most part, but sometimes I’m still animating with it, thought it would be good to make this easily and quickly reference-able just in case:

The Form:

<form id=”enewsform” name=”enewsform”>
<input name=”first_name” id=”first_name” type=”text” value=”First Name”/>
<input name=”last_name” id=”last_name” type=”text” value=”Last Name”/>
<input name=”email” id=”email” type=”text” value=”Email” onFocus=”if(this.value == ‘Email’) this.value = ”;” onBlur=”if(this.value == ”) this.value = ‘Email’;”/>
<div id=”hp_email_loading” style=”font-size:11px;display:none;”>Loading… please wait.</div><br />
<span style=”font-size:11px;”>Your email address will be kept strictly confidential.</span><br /><br />
<img style=”cursor:pointer;” onClick=”enewsSubscribe(); return false” onMouseOver=”this.src=’images/submit-over.gif'” onmouseout=”this.src=’images/submit.gif'” src=”images/submit.gif” alt=”Submit”>
</form>

The Javascript:

function enewsSubscribe()
{
var email = document.getElementById(’email’).value;
var first_name = document.getElementById(‘first_name’).value;
var last_name = document.getElementById(‘last_name’).value;
new Ajax.Updater(‘hp_email_box’, ‘filter.php?email=’ + email + ‘&first_name=’ + first_name + ‘&last_name=’ + last_name //);
, { onCreate: show_subscribe_loader, onComplete: hide_subscribe_loader });
}

function show_subscribe_loader()
{
document.getElementById(‘hp_email_loading’).style.display = ‘block’;
return false;
}

function hide_subscribe_loader()
{
document.getElementById(‘hp_email_loading’).style.display = ‘none’;
return false;
}

Googlebot make your AJAX crawlable #! simply explained

Tuesday, April 13th, 2010

http://code.google.com/web/ajaxcrawling/

But what?

Put simply, in your URLs, that are currently:

http://www.site.com/index.php#page90

First, make them:

http://www.site.com/index.php#!page90

Your Javascript will just see the ! (bang) as a character, it won’t care, and will continue to work just fine

Googlebot though, sees the ! and changes its query to:

http://www.site.com/index.php?_escaped_fragment_=page90

So your index simply needs to see $_GET[‘_escaped_fragment_’]

If it’s set, load page90 via PHP instead of AJAX, and there you have it,

now Google will link the content it found via:

http://www.site.com/index.php?_escaped_fragment_=page90

to the url:

http://www.site.com/index.php#!page90

Now alter/resubmit your Google Sitemap so that all your URLs are current (WITH the #!) and you’re set!

AWESOME!

Javascript HTML form field onFocus onBlur

Tuesday, April 13th, 2010

<input name=”email” id=”email” type=”text” value=”Email” onFocus=”if(this.value == ‘Email’) this.value = ”;” onBlur=”if(this.value == ”) this.value = ‘Email’;”/>

PHP include() doesn’t pass variables!

Saturday, April 10th, 2010

Really wanted it to…

Seemed logical enough…

index.php: <? include(‘some_file.php?id=3’); ?>

some_file.php: <? echo $receive_id = $_GET[‘id]; ?>

BUT ALAS, NO

Alternatively, simply set the variable, and the included script may access it just as though it were the parent script…duh.

PHP include $_SERVER[‘Document_Root’] include_once AJAX

Saturday, April 10th, 2010

It can be tricky if your include statements don’t always load from the same location in the app, an include(‘that.php’) in the root index file thinks of itself as coming from the index, so anything included THEREIN will too, but then if someday down the line you want to call an evaluation script, for example, and THEN the rest of the application…a bunch might break.

Thus, with EVERY include, it’s best to use one of the available SERVER variables, which is a longer story, but here’s an example:

include($_SERVER[“DOCUMENT_ROOT”] . “/site/lib/logic.inc.php”);

The next lesson, logically following, is that this new evaluation script needs to load in the app’s functions…but it thinks the second load (which of course only happens SOME of the time via the evaluations…) is trying to redefine the functions, HENCE:

include_once

Prefer it.

Finally, you’ll notice that includes are affected differently when loaded via AJAX.  For example, index.php loads in our new evaluation.php, which then loads 1.php or 2.php and so on, that is, when the app is being loaded exclusively by php in order to be crawled by Googlebot, but if it ISN’T Googlebot visiting it this time, let’s load things via AJAX!  Short and sweet, use the above mentioned $_SERVER[‘Document_Root’] everywhere BUT in your JS, and use full paths if possible INSIDE, as such: http://localhost/includeLesson/pages/page1.php, or similar Server variable to sidestep this mess, and now you can recognize these pitfalls when you encounter them, or remember their solutions next time they cross your path (by which time of course you’ll have forgotten how you solved them last…)

PHP 301 redirect forward

Thursday, April 8th, 2010

<?

header(“HTTP/1.1 301 Moved Permanently”);
header(‘Location: http://www.google.com’);

?>

jQuery fancybox iframe syntax

Wednesday, April 7th, 2010

<head>

<script type=”text/javascript” src=”js/jquery.js”></script>
<script type=”text/javascript” src=”js/jquery.fancybox.1.2.1.js”></script>
<link type=”text/css” href=”css/fancybox.css” rel=”stylesheet” media=”screen” />

<script>

$(document).ready(function() {
$(“a#iframe”).fancybox({
‘speedIn’ : 600,
‘speedOut’ : 200,
‘padding’ : 20,
‘overlayOpacity’: 0.7,
‘overlayColor’ : ‘#FFF’,
‘titleShow’ : false,
});
});

</script>

</head>

<body>

<a id=”iframe” href=”The_Power_of_Meditation_Tracks.html”>View Tracks &raquo;</a><br />

</body>

PHP remove price and/or decimal and zeros Trim and substr methods

Monday, April 5th, 2010

Trim method:

<?

trim(trim($num, '0'), '.');

?>

substr method:

<?

$num = number_format($num, 2);

if((substr($num, -1)==0) && (substr($num, -2)==0))
{
$num = number_format($num,0);
}
else
{
$num = $num;
}

?>

quick note: Javascript equivalent to PHP isset variable

Saturday, April 3rd, 2010

Check to see whether or not a variable has been declared

if ( typeof ( $variable ) == ‘undefined’ )

{}
else
{}