Web Development

Web Development Tips & Tricks, the things that you don’t want to figure out.





Archive for May, 2007

Shopping Cart – Closing in!

Wednesday, May 30th, 2007

The shopping cart I have been developed hit a major slow a couple weeks ago and I couldn’t find a solution, which is very rare. Well, a couple days ago I looked for a PHP forum. This was after I had given up on 1&1 support after many calls and many emails, Paypal thought it was on my hosting end and wasn’t getting many responses and other companies told me to switch hosting providers.

Well, I explained my situation and in about a 24 hour period they figured it was my cURL version was old because it was an old PHP version (4.4.7) on the dedicated SSL. I had tried to get 1&1 to upgrade this before using .htaccess, but your .htaccess files don’t affect your SSL server. I now knew that I had to get it upgraded for it to work.

I was thinking about this for a while. In the mean time I sent a support request to Paypal seeing if there was any alternate solution to using the old cURL version (they didn’t really know what I was talking about) and sent a request to 1&1, thinking I would just badger them a bit more, hoping someone could change it.

Before I go on, I thought I should comment quickly on 1&1. After asking them how to upgrade to the higher PHP version, I explained the reason being I needed to upgrade the cURL version.

They responded and told me I needed to upgrade my PHP version. I responded saying that I had asked that question, and I needed to know how.

Next response tells me that sorry, but you can’t upgrade your PHP version. Great, well I already had another solution worked out, I just didn’t like it.

PHP 5 has its own extension “.php5″. I tried this on the server and it did support it, meaning 1&1 had lied again. This handled my problem and I was able to connect successfully to Paypal! Yes! Now I just have to finish implementing WPP (Website Payments Pro).

-Kerry

P.S. I also have another script that I will be blogging about soon. It generates Atom and RSS 2.0 feeds, but its not in a finalized form though it does work correctly.

The Use Of Includes (PHP)

Monday, May 28th, 2007

It’s a very basic concept but often omitted, making life much more difficult than need be.

A basic principle that I follow is to never repeat identical code. If you have to repeat identical code somewhere, you should use an include, which will save you a lot of time and effort.

So, what is an include? It is a file that has a portion of text that you plan on using repeatedly throughout your site. For instance, the footer of your site that contains perhaps a few navigation links and your copyright is a great idea for an include. Lets say you have a very basic page, something like this:

index.php

<html>
<head>
<title>Include Example</title>
</head>
<body>
<img src=”example.jpg” />
My great website!
Copyright Joe Smith. All Rights Reservered
</body>
</html>

You can put that bottom copyright into a file, lets say footer.php (all my files are php, you can use any extension, .htm, .html, etc).

footer.php

Copyright Joe Smith. All Rights Reserved.

Now, to make this more interesting, lets say we added in some navigation at the bottom:

footer.php

HomeLinksAbout
Copyright Joe Smith. All Rights Reserved.

To include this file (remember that I’m using PHP, there are alternate methods in other scripting languages), your original page would now look like this:

index.php

<html>
<head>
<title>Include Example</title>
</head>
<body>
<img src=”example.jpg” />
My great website!
<?php include(“footer.php”); ?>
</body>
</html>

This puts all the code in footer.php right in that page. No visitor can see your php code – in this case it gets replaced by the code in the file, so it looks like a completely normal page. This enables you to put that little php include at the bottom of all your pages, and they all use the same page, so you never have to repeat that code. Now, if you change something in footer.php it will change that code on every page in your site. Most of my pages look something like this:

index.php

<?php include(“header.php”); ?>
<div id=”leftcolumn”>
<p class=”pagetitles”><b>Unsatisfied with your website?</b></p>
<p>Whether you finally decided to bring your business or career to the web, or you feel your website isn’t reaching
full potential, we can help.</p>
<p>We will build a website from ground up, walking you through every step on the way. If you want a site with
Flash Animation, E-Commerce, Support Forums, Wiki, User Login, etc., we will do it for you, completely customized
to your wish.</p>
<p>We will take care of any touch-ups or new features you need on your site – we constantly develop features for websites
or implement highly customizable ones to match your needs.</p>
<p>If you are a Web Designer but need the back-end taken care of, we will handle that. If you’re a developer and need the
design taken care of, or you need help with a specific section of your site, that will be arranged.</p><br /><br />
<br />
</div>
<? include(“footer.php”); ?>

header.php

<!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>Phoenix Development</title>
<meta name=”description” content=”Phoenix Development offers professional web design and development services for both personal and commercial websites.” />
<meta name=”keywords” content=”web design, web deveopment, phoenix development, php,” />
<link href=”/css/stylesheet.css” rel=”stylesheet” type=”text/css” media=”all” /><!–[imcss] *** Infinite Menus Core CSS: Keep this section in the document head for full validation. –>
</head><body><div id=”wrap”>
<div id=”page”>
<div id=”textarea”>

footer.php

</div><div id=”footer”>
| <a href=”/” title=”Phoenix Development Home”>Home</a> |
<a href=”/about.php” title=”About Us”>About Us </a> |
<a href=”/services.php” title=”Services”>Services</a> |
<a href=”/testimonials.php” title=”Testimonials”>Testimonials</a> |
<a href=”/referrals.php” title=”Referrals”>Referrals</a> |
<a href=”/faq.php” title=”Frequently Asked Questions”>F.A.Q.</a> |
<a href=”http://phoenixdev.wordpress.com/” target=”_blank” title=”Phoenix Development Blog”>Blog</a> |
<a href=”/contact.php” title=”Contact Us”>Contact Us</a> |
<br /><br />
<br />
© Copyright 2007 Phoenix Development. All Rights Reserved.
</div></div>
</div>
</body>
</html>

I removed a little bit of code from my website that has more advanced features. If you want to learn about those, let me know.-Kerry

htaccess – Securing a Folder

Saturday, May 26th, 2007

Ever wondered how to get that little box to pop up before you access a page, insisting that you enter in a username and password? Well, here’s how:

One of the first things you need to do is create a username and password, and there are many places that do this. This .htaccess Password Generator also gives you brief instructions in case you forget later on.

It’s going to ask you to create an .htaccess file, this is simply a text file that is only an extension. Here’s an example of the code that would go in it:

AuthName “Example Section”
AuthType Basic
AuthUserFile /usc/www/.htpasswd
require user example

The AuthName can be changed to anything. It’s just lets you know what section this is securing. Now, the AuthUserFile can be difficult. You need to get the path extension on the server to your soon-to-be .htpasswd file (its like .htaccess in that it is also just an extension). Your .htpasswd file should be in a directory below your website. For instance, if your hosting provider lets you have access to the root directory (“/”), and you put your website in “/website/” folder, you would put your .htpasswd file in the “/” directory, meaning it is not accessible off your website. Your website can access it because its on the server, but no where on your website can it be accessed (this is for security purposes).

Now, to get the path to your .htpasswd file you need to get the server variable document root. Simply put this PHP code on a test page (like “test.php”):

<?php echo $_SERVER['DOCUMENT_ROOT']; ?>

That is going to give you a path like this: “/usc/homepages/52/d167925675/htdocs/website”. Now, hopefully you managed to put your .htpasswd in a directory below your website, so this would make AuthUserFile look something like this:

AuthUserFile /usc/homepages/52/d167925675/htdocs/.htpasswd

The last line can vary. You can setup multiple usernames and passwords, if you want any of them those usernames and passwords to get access to this folder, the last line would look like this:

require valid-user

If you want a specific user, you specify the username:

require user admin

Now, your .htacccess file should look something like this:

AuthName “Example Section”
AuthType Basic
AuthUserFile /usc/homepages/52/d167925675/htdocs/.htpasswd
require user admin

Upload your .htaccess file to the folder you want secured. The next part is the contents of your .htpasswd file, which should contain the code generated by your Password Generator. If you put in the username admin with a random password, the generator should return a line like this:

admin:$1$GfdY8TeD$7mQP0niEKyKw1AIfq3Sh40

Save that line in your .htpasswd file. If you want more than one user, generator another password for another user and just put it in the next line. You can have as many users as you want:

admin:$1$GfdY8TeD$7mQP0niEKyKw1AIfq3Sh40
bob:$1$Io1beImD$fzX1R0OuyF.tx93BXOYun/
jennifer:$1$.0yS.o4t$ozvF/On0AomFSIxJ1HUx80
jimmy:$1$RC3tDZPt$ZxWEad3cZ74G9l9e3/7q71
guest:$1$glop/HIQ$8PdBnCwpSwcqFS30mY2Dl0

Now, upload your .htpasswd file to that root under your website. Your done! It should now require a password.

If you find that your password isn’t working and now you’ve locked a section of your site and can’t get in, simple remove the .htaccess file from the folder that its in, and everything should return to normal.

If you need additional assistance, feel free to contact me.

-Kerry

Favicon.ico with Photoshop

Thursday, May 24th, 2007

Photoshop, atleast 7.0, doesn’t natively support cursor files (.cur) or icon files (.ico).

To solve this little problem I downloaded a little freeware utility that can handle .ico’s. Well, I was simply looking to find out what size the favicon.ico was supposed to be when I came across a tutorial gave a much better solution.

It’s a Photoshop tutorial for favicons. It shows you where you can get a free plugin for Photoshop that lets it handle icons and cursors (really easy to install). It also tells you all the information you need to know about favicons and gives you links and resources to see some of the great ones out there. I really suggest doing the tutorial: How To Create A Favicon.ico.

That’s it for today,
-Kerry

Phoenix Development – Site Design!

Tuesday, May 22nd, 2007

The design has arrived! Thanks to Rafferty Pendery and Studio 98 Designs, I have a beautiful website design! You can see it at Phoenix Development home page. I will be putting up content soon, as well as a list of all my services and all the scripts I’ve been working on.

It’s a little bit ironic how so many web developers and web designers have errors on their website or simply incomplete cycles. Most of the time they are busy with so much other work that they don’t have enough time for their own site, but I think its important to set a good example. Phoenix Development will live up to that standard.

-Kerry

PNG Transparency in IE

Monday, May 14th, 2007

I’ve run into a lot of trouble with this aspect in the past, namely onHover events with transparent buttons.

If you’re getting excited because you think you’re reading the solution – take it down a notch. Yes, I know how to do that, but that’s not what this blog is about. My solution to the above problem will lag the browser a little bit, not that noticeable, but definitely irritable.

This post is to handle the problem of simply displaying transparent PNGs in IE. Well, you have to use CSS and call a filter that allows transparency. That’s a simple fix.

The other day my friend, Rafferty Pendery, ran into this solution, which I thought was far better and wanted to show it to you. This page has the solution: PNG in Internet Explorer: How To Use. Basically, they are giving you a Javascript that automatically goes through all your pictures on the pages and checks if they’re PNG. If they are PNG, they give it the CSS filter.

All you need to do is include the Javascript file and all your PNGs will display their transparency.

Are you wondering why you shouldn’t use a GIF, which also supports transparency? A GIF doesn’t keep the same quality of color as a JPG or PNG unless its solid lines. If you’re creating some cartoon animation, great, use a GIF. If you are using a high quality picture you should use a JPG or PNG (JPG compresses better, but doesn’t support transparency.)

-Kerry

PHP – cURL

Wednesday, May 9th, 2007

My post today is actually not a complaint nor instructive.

Yesterday I decided I was going to figure out how I could post through a proxy server. Right before I went to bed I found the functions cURL but didn’t have enough time to thoroughly explore it, which I did today.

cURL stands for Client URL and is a very powerful too. You can send all sorts of different requests to other servers and get all sorts of information.

In the tutorial I did today, he goes over how you can get definitions from dict.org (a dictionary site) or from amazon.com with requests based off input. Of course, you have to know what’s needed on the other end, but that information is out there. You can use it to FTP files back and forth. In my case I liked the posting ability. You can post data to another server.

I had been looking for this data for months, never really trying hard, just a couple searches here and there. This is it. Instead of giving you a bunch of code how you can do it, I’m just going to refer you to this tutorial: Using cURL with PHP. He briefly goes over all the things I was telling you about, but he does assume you have a little bit of prior PHP knowledge and experience.

Of course, like most great function sets (it’s not a specific function, its a set of different functions), it has its own home page.

I hope this discovery is exciting for you as it was for me.

-Kerry

1&1 Support

Monday, May 7th, 2007

It’s not something to count on, that’s for sure.

As most of you know I’ve been trying to install a shopping cart using Paypal’s Website Pro setup. Well, I basically finished developing it up to the point where I am submitting the credit card information to Paypal. I then ran into a barrier. Apparently 1&1 blocks post requests from a secure server, you have to use a proxy. Other people talk about it on Paypal which is how I found out about it.

So, I send them a support request asking for their help. They sent me a reply on how to set up my SSL certificate… apparently that didn’t get my question.

I called them up, and explained my problem. After I fully explained it, the girl said “let me pass you over to tech support”. I said “ok” but was slightly confused as I had dialed the tech support number, but it seemingly doesn’t go to them. Then a woman with a thick accent picks up the phone and I have to fully reexplain my problem, and because we can’t understand each other that well, it takes more time. She ends up saying that she will have to ask her supervisor.

So she puts me on hold for several minutes, comes back and tells me something that completely didn’t answer my question. I explain it again. She says she will have to go to her supervisor again, and puts me on hold for several more minutes. Unfortunately, I made the mistake of pressing the key to hang up instead of unmute myself at this point, and I knew they didn’t really keep logs of this and there was no way I could call back that same person, so I gave it up. I had spent 20 minutes on the phone and gotten absolutely NO WHERE.

This is just one of many problems I’ve had with their support. They also specifically told me that they do not support letting your web page have some pages that are secured by SSL and others aren’t. They gave me a reference to turn my whole site into SSL, or none of it. At the time, for whatever odd reason, maybe the SSL hadn’t been completely setup, it wouldn’t let me go to a specific page as https://, I had to turn my whole site into a secured site. Well, I didn’t believe them . After I got off the support call, I decided to try again.

They had rewritten my .htaccess file. They never told me they were going to override it, I had a lot of code in it besides the part about the SSL. They erased valuable code, and it took me a while to hunt it back down again and getting the site running as it was supposed to run. I then proceeded to go to my website, having it be optional SSL or not secure (what I wanted), and it worked. They had lied, whether they knew it or not.

1&1 has great price and good hosting features and everything like that. Do not expect good support.

-Kerry