Wednesday, January 14, 2009

Why I hate Blogger!

This is just a rant but blogger is terrible.  It has the worst text editor ever created for a blogging software.  The list can go on but I think we're going to switch to something new as soon as we have some free time (if ever!).

Wow, I just need to vent because it is a pain to use blogger.  I don't recommend it!

IE6 Problem with Form Submit Image Buttons

A lot of times we use images as our submit buttons for forms. I'm sure you've seen it a lot. Well, say you wanted to test if the form was submitted and used the standard way, lets say in PHP, of seeing if the submit button was sent, for example like this:

if (isset($_REQUEST['mysubmitbutton']))
{ ...}

With IE6 this wouldn't work if your submit button was an image. So if you had this as your submit button:

<input name="mysubmitbutton" type="image" value="1" src="someimage.png" alt="" />

Then your script wouldn't work. The reason is that IE6 WILL NOT send over the variable mysubmitbutton.

The workaround is to know that IE6 will send over other information (along with all other browsers). It sends the x and y coordinates of where you clicked on the image. So you'll see mysubmitbutton_x and mysubmitbutton_y. So if you modify your code to look for either of these variables, you'll be good to go!

Credit is to be given to this discussion forum: Differences in form handling btw Mozilla and IE?

Thursday, January 8, 2009

Get referrer with PHP

Here is some code to find out the referrer to a page in PHP.  This can be very useful if you want to redirect back after login or something like that.  You can also set it up to make sure a visitor came to the page from within your site or something like that.

<?php
session_start();

if(!isset($_SESSION[’referrer’])){

//get the referrer
if ($_SERVER[’HTTP_REFERER’]){
$referrer = $_SERVER[’HTTP_REFERER’];
}else{
$referrer = “unknown”;

}
//save it in a session
$_SESSION[’referrer’] = $referrer; // store session data
}
?>


Hope this is useful.  The reference is: Get a referral URL from the session using PHP

Monday, December 22, 2008

Making a Link Select a Select Box in Javascript

I needed to have a link select an option within a selectbox.  What I wanted to do was have a bunch of links out there and if a user clicks one, move down the page and have a value in my selectbox already selected according to that link.

I found a solution online that worked great.  It uses javascript, but works wonderfully.

Since blogger doesn't let me paste code easily, I'll just direct you to the link.  If it ends up being dead in the future, please leave a comment and I'll post the code.



Tuesday, December 16, 2008

Server Root Path with PHP

Here is a simple way to get the server root path with PHP:

$_SERVER['DOCUMENT_ROOT']

Say you want to check if a file exists, you could do this:

file_exists($_SERVER['DOCUMENT_ROOT']."/yourfolder/yourfile.extension")

Putting this in an IF statement will see if the file exists.  If it does, file_exists will return true, else it will return false.

Friday, December 5, 2008

Trim Whitespace in PHP

Trim is a nice built-in function for PHP.  My default it will trim off the whitespace from the beginning and end of a string.

Description

string trim ( string $str [, string $charlist ] )

This function returns a string with whitespace stripped from the beginning and end of str . Without the second parameter, trim() will strip these characters:

  • " " (ASCII 32 (0x20)), an ordinary space.
  • "\t" (ASCII 9 (0x09)), a tab.
  • "\n" (ASCII 10 (0x0A)), a new line (line feed).
  • "\r" (ASCII 13 (0x0D)), a carriage return.
  • "\0" (ASCII 0 (0x00)), the NUL-byte.
  • "\x0B" (ASCII 11 (0x0B)), a vertical tab.      

Returning Content to PHP Variable with cURL

I have a few examples of using cURL here in PHP but this parameter allows you to store the content of the selected source to a PHP variable.

Say, for example, you are loading up a page with cURL and want that information store in a PHP variable to use throughout your site.  You can do this by adding the following code to your cURL request:

curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); // return the page content

So here is a full block of code:

$curl_handle=curl_init();
curl_setopt($curl_handle,CURLOPT_URL,'URL_TO_THE_PAGE');
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
$savedvalue = curl_exec($curl_handle);
curl_close($curl_handle);

In this case, $savedvalue will hold all the information returned by that page request.

cURL is very powerful and worth learning about.  Here is a good resource: PHP login/download file - CURL libraries.