Web Development

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





Archive for January, 2008

Deezer – Unplayable Songs (Hack)

Thursday, January 31st, 2008

For those of you that don’t know, Deezer is a website that allows you to play a huge selection of songs by huge selection of artists for free, no questions asked. You can also create playlists and so on, if you register an account with them.

(If you want to skip all the preamble just go down to the code section and you’ll see code that will fix the Deezer problem. If you have no idea what I’m talking about, continue reading.)

But, it is a very weird site. They’ve changed their layout a few times, it used to be “blogmusik.net”, but they’ve always been buggy. Apparently it’s run by someone in France as many of the writing is in French, which is often quite confusing.

Most people can ignore all these oddities as they can still search and play music.

Well, quite some time ago there were “grayed-out” songs. Meaning you couldn’t click on them anywhere. There was no support saying why they were that way, no FAQ, no instruction. It annoyed a good many users, including myself, so I went to the forums and found a simple work around. You could right click and say “Play This Track” and it would play.

I thought it foolish of them to have unexplained grayed-out songs that could be played with a right-click. I used this for many months, then I was informed they changed their layout.

Sure enough, next time I went to play a song from them, different layout, and you could no longer right-click to play a track, but there were no longer grayed-out songs. There were songs that simply wouldn’t play.

Well this was worse, again, nothing in the support or anywhere on the site saying why you couldn’t play these tracks. Some people on the forums reported adding them to a playlist, and then playing them would help. This, however, was not a universal solution.

I found, on the forums, someone who wrote a line of javascript to copy and paste into your browser, click “enter” then refresh your page, and it will work. I thought it was a weird solution, but worth a try. It worked!

With no further ado, this is the code:

Copy and Paste Into Address Bar

javascript:function SetCookie (name, value){var aujourdhui = new Date();var expdate=new Date();expdate.setTime(aujourdhui.getTime()+(24*60*60*1000));document.cookie = name + “=” + value + “;expires=”+expdate.toGMTString()+”;path=/”;}SetCookie(‘COUNTRY’, “FR”);

I haven’t inspected this code thoroughly, but basically it looks like it sets your cookies to make it look like you’re from France.Today, I found out something strange. It was the first time I had used Deezer on a new computer so I knew I had to find that code again. It was not in the forums, and other people were asking for it, and someone noted that a moderator removed it. Apparently, in that forum someone posted it again. By the time I got there, it was removed.

My father had saved this code away in a google document, so I asked him for the link and used it. Yep, still worked. So, this is my “protest”, so to speaker, to their unexplained censorship. If they were kind enough to explain why they had unworking songs, why they didn’t want the code around, I could respect their wishes, but at the moment it seems very illogical.

-Kerry

Browser-Specific CSS

Saturday, January 26th, 2008

If you’ve done much with CSS at all you know that the IE’s not only display differently than Firefox, but IE7 displays differently than IE6.

Instead of using Javascript or another scripting language to determine what browser is being used, there are a few simple techniques that can handle that problem for you. This works inline or through an included stylesheet.

CSS

h1 {
font-size: 20px;
#font-size: 22px;
_font-size: 10px;
}

The first applies to all browsers, Firefox, IE7 & IE 6. The second applies to IE7 & IE6. The last applies to only IE6. This means that if you define them in the order I have given you, the top only effects Firefox, while the second line only affects IE7 and the last line only affects IE6.-Kerry

PHP, Cookies, MySQL & Headers

Monday, January 21st, 2008

I was recently implementing a persistent login feature and stumbled across a website that did it in a more unique way, seemingly more secure: Persistent Login Cookies Best Practice. I thought it was a smart way to use cookies and decided to use it.

Now, the way IÂ set my system up was that someone would enter a username and password, which it validates and then sends a request to my MySQL database to make sure that it matches. Upon matching, it sets a cookie using the method mentioned above.

One things I do is I like to use includes to store variables procedures, etc. I always, always, store database connection data in an include. I don’t like to have any data on a page where someone in a passing glance at my screen could get that information, or something of that nature. So, just like any other page, I included the database connection, sent the queries out, then tried to set cookies.

I received the error “headers already sent out”, pointing to my database connection include. This lead me to believe that the functions themselves sent out headers, and so I would have to some weird way of settings cookies like reading another page with it as a query string and a lot of unneeded complexity would be added.

I decided to mention my problem to an ASP.NET programmer, who didn’t use cookies much and we ended up arguing because he wasn’t understanding my problem. In a fit of frustration, I replaced the contents of the include with the call to the include – meaning the database connection data was now on page.

It worked.

Why did this work? I didn’t know. This led me to believe that including a file sent out headers. So, to prove my point, I included another file.

It still worked.

I then thought because the other include I was using only contained variables, and the database connection include called a function, that you couldn’t call a function within an include, because that would send headers out.

Wrong again!

I did more tests and finally gave up trying to exclude the database login information in an include. I still don’t understand exactly why, I even tried to store just the variables of the information and then do the calls in the program, which didn’t work.

I continued with my work, going on to other things, and had the magnificent thought, why don’t I put the setcookie (PHP function) in with the database calls in an include file? This will save me extra code and will keep the database information secure — if it works.

It worked!

In conclusion, if you need to set cookies after making a database call and would like to keep your database login information secure, use some sort of of function, either within a class or just a function that will make the call for you.

-Kerry

What’s new in ’08?

Tuesday, January 15th, 2008

The new thing is Social Marketing, and StomperNet says it best. It’s been building up for a few years and now it’s time to take advantage.

This video has changed my world, and many others in the area: Going Natural 2.0. I am not getting paid to advertise these guys, not in the last (that would be fun), but that video has been the cause of revolution in my thinking and marketing ideas.

More Social Marketing posts will be coming up, but right now that video should get you started. While I don’t believe this replaces SEO in the least, I do think it VERY much changes the game.

-Kerry

I’m back!

Wednesday, January 9th, 2008

So I took an extended Holiday Vacation from my blog and have been… missing. I know I commented on upcoming things which fell through. I may post those, I may just move onto bigger and better things. I will continue with the programming tips, tricks & bugs, and I will be adding more about marketing in this internet of ours.

This is a small post, but I have other data in mind, which I could post right now, but I’m going to hold off for the moment – when I get a better understanding of what I’m talking about, I will give some posts so you don’t have to be as enthusiastically confused as I sometimes get.

Sincerely,
Kerry