Posts Tagged ‘PHP’

Complete (Un)Success!

Wednesday, May 27th, 2009

I’ve been playing around with CSS3, lately.
One very specific thing I do is make images that are a bit larger than they appear on my screen, because I know people are going to set their text sizes differently. Another thing I do is scale things depending on width or such, so that everything fits the best it can.

With today’s background-images, the image is rendered at 100% zoom even if you want it in a smaller box. That means I need to put images in my markup, or at least it means I can’t just switch them out using only CSS.

This is where CSS3 comes in: Konqueror, Opera, Safari, and Chrome can set background-images to specific widths and heights. I just set visibility:hidden on my old image, and copied the width and height to my CSS background-image (in this case, background-size:100% auto). Voila!

If you’ve visited using Webkit or Gecko, you’ll notice that I have rounded corners. That means the corners are square for Opera, Konqueror, all IE versions, and whatever else. This CSS image replacement doesn’t work in Firefox or IE (strange how Firefox is missing support on it), which makes it look terrible in those browsers. It’s not something that you could put out publicly.
Altogether, this means my page only renders correctly in Webkit. That’s about… 5% of the total market?

I guess I’ll be stuck hacking up some PHP for my page bodies. For those of you who want to see my simple little session-switched thing, you can visit Cozy Cabbage, then put a ?grey in the address bar, and then ?green to switch back.

Photo Gallery

Thursday, May 21st, 2009

I just finished more work on the old Atomicat Photo Gallery.
I was working for him last year, basically, at the same time as I was take what was essentially my first every-twenty-years-vacation. I figured I’ve been going to school since I was four or five, and I’ll probably be working until retirement, so I might as well take a year off to do some other stuff.

The site was the first website I’ve ever designed, and went through a couple drastic redesigns. I created the modern logo, which I’d say is fairly decent, and experimented with things like floats and whatever else.
The CSS on that site is disgusting. I didn’t really ‘get’ the id attribute, and so I had classes in every little thing. Extensibility was fairly unneeded, so I would end up creating a little class to do one thing, and then paste that on whichever element needed to do that. The result was something like HTML with half the semantics of HTML. Is <div class=”floatl”> any better than <div style=”float:left”>? It seems I’d completely ruined the core idea behind CSS.

The gallery was something else: Hours upon hours of hand-crafted goodness, as from a seamstress who turns away the sewing machine to make each careful stitch with her own sure hand.
In short, it was a mess. There were eight pages to be taken care of, each with images that had to be named specifically for that page. Any images you wanted to add had to be specially named for yet another page. Each item had to have the name/description engraved in the html, to be passed in an ugly GET variable.
Tonight, I went through the motions of creating the database and putting everything in it. I took every bit of repetition in the gallery and put it in loops. The gallery went from seven pages to one; the page went from eight individual items to two (I could probably turn that to one); and that item or two is loaded in from SQL.

I guess I’ve still got to do tags, but I’m finished for tonight. I’ll have to eventually upgrade the entire site up to my current standards, and then upgrade it again to the standards I’ll have by the time I’m finished.

This is shaping up to be quite a year.

More Twitter?

Monday, May 11th, 2009

“Not again!” you all groan. Well, a couple of you.

I was thinking about URL shortening again, and then I realized that what everyone has been thinking about misses the mark just a little. Sure, you could set up something where you enter your site-admin or an FTP window or whatever, and then edit a file to include one more line, but the odds are it’s not you who’s going to use the service. What if you had a path to your shortening service (.com/shortener.php) that you could give a service like Twitter, and then Twitter could take your long URLs you enter from your mobile device while you’re somewhere doing something that leaves you in no mood to try hacking that into your website first.
What if you could just put into a box on your settings page, and if you happened to tweet a long string it would just use that service, instead of sending it to TinyURL?

If you put it in those terms, your requirements for your shortener change. It must accept a value from a site (probably as a POST variable), maybe check if it’s actually a URL, certainly check if it came from a list of allowed sites (you don’t want some random person throwing spam link into there, to use on other people), write that to an index, generate a new short URL, save that to the index, and then send the result back to the requesting site.

Then that site can put your shortened URL in place of the longer one, and you don’t have to worry about completely-ambiguous URLs; only mostly-ambiguous URLs.
It’ll give you the peace of mind that someone will at least know what site they’re going to, just by looking at the link.

As for the ‘how’: I’ll get to that later. I have to try some things out with PHP, first.

Twitter? PHP? Yes!

Wednesday, April 29th, 2009

I’ve heard from a lot of people that twitter shortens URLs, apparently if they’re more than 30 characters. This means that something like would take the full 30, even without an image. I’ve taken a look into what you can do to shorten the URLs you use for your own images:

  1. Top-level domains: If you use instead of, you can slash four characters
  2. Root image folder: If you place a folder for your twitter images in your root, you can point to that folder, such as or
  3. Invisible PHP: If you have a index.php in your folder, you can go to and the server will find the index for you. Send it parameters, such as i for image name, and either g, p, or j for .gif, .png, or .jpg, respectively:

In that final example, the URL is exactly thirty characters long.

For those who want to the PHP script, I have it below:

list($key, $value) = each($_GET);
if(isset($key) && $key != 'p' && $key != 's' && $key != 'm' && $key != 'cat')
{ //wordpress uses 'p', 's', 'm', and 'cat' for posts

$pretension = "<img src='img/twitter/";
$extension = ".bmp' />";
$extension = ".gif' />";
$extension = ".png' />";
$extension = ".jpg' />";

header("Location: http://www.".$key.".com/");
echo $pretension . $key . $extension;

}else{/*do regular index stuff */}

In this snippet, I paste it before the stuff of my wordpress index. certain GET keys are taken by WordPress, so those can never be my first key. As long as it isn’t, it’ll accept it as a short url, and you can use ‘p’ or ‘cat’ or such as the second or later key. Go to to try it out. I’ve set it up so that ‘s’ means the sites I’ve made (I’ve made two, so 1 and 2), followed by a design revision (I only have one recorded on s1, but I have four revisions on s2). So try changing that from s2a to s2b, s2c, or s2d. The ‘p’ at the end denotes a .png file. If you put ‘h’, it’ll take it as an HTML page and redirect you.

If you’re the intensive type, you could set up an array on that page which will match the $key to a list of longer filenames in an associative array, which would let you not rename everything. If you’re referring to other sites, you’ll have to do this.

The way I see it, the shortest you could go is to put
in which you have a maximum of 62 links ($key, from the above PHP example, would be a-z, 0-9, or A-Z), all of a pre-determined type. You could get a four-letter domain-name and something like .ca to shorten it further. Overkill? Yes; but I’m just saying, thirteen characters are possible.

So here’s the challenge: make yourselves or your clients a page where you upload an image, that image is placed in a ‘twitter’ folder in the images directory, the filename is added to the array, the user is given a link to paste, and the there’s some $_GET code in the index.php file that takes a visitor to the content described by the link. I’ll have to throw my own implementation up, though it would be completely useless for twitter while I have such a name as icosidodecahedron (seventeen characters).
I’ll try importing html files, too.

…And in with the new

Wednesday, March 11th, 2009

Compare Before with after:

At least it’s not total crap, anymore.

I’ve been looking at CakePHP, as I may have mentioned before, and it seems too much for me. I should work on jQuery, first.
PHP needs a server, so I’d have to upload it to my website every time I wanted to test something.

I’ve also realized that I need to add those clothing items (at with php, instead of javascript, because having scripts off shouldn’t completely change the working of the page. If anything, the script should at most insert some events here and there to enrich the experience.