Jump to content

Best Practice Way to Handle url encodes?


limitphp

Recommended Posts

I have links that have artistName and songName in them.

Right now I have a column that has artistNameHash and songNameHash and those are what I use for the links.

ex)

mysite.com/comments/$artistNameHash/$songNameHash

 

when I add the artists and songs to the database, thats when i manually add the songNameHash and artistNameHash.....there are no set rules I use....

so far I'm replacing spaces with dashes and single quotes with underscores....I haven't had any other symbols yet...because I'm just using test songs so far.

 

so, my mod rewrite handles underscores and dashes.....

 

I'm thinking I should change it to handle it like this:

add the song name and artist name to the database when I add the song.

 

Don't worry about adding a songNameHash and artistnameHash column to my database.

 

When I need to link using the songName and artistName, run both through the urlencode and use that:

ex)

$url_artistName = urlencode($artistname);
$url_songname = urlencode($songName);

mysite.com/comments/$url_artistName/$url_songName/

 

and then, fix the mod rewrite to accept all the characters urlencode throws at it.

 

When the request comes in:

$artistName = $_GET('artistName');

it'll get converted back automatically into the original artistname, correct?

 

does this sound like the better way to do it?

 

thanks

 

Link to comment
Share on other sites

I prefrt using the id, since almost all tables have a id INT(11) AUTO_INCREMENT field.

But yeah, why make a id/hash system if ya dun use em

 

 

I would assume to not use the id, since we want the site to be SEO friendly.

 

The hash names were going to be used to fix the artistName and songName to make them ok for url....

 

but I figure why enter in each hash name manually, when urlencode will take care of the problem for you?

 

the only thing is, the percent and urlencode might mess up the adobe mod rewrite.....

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.