Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 08-24-2007, 04:12 PM   PM User | #1
webosb
New Coder

 
Join Date: Jun 2007
Posts: 28
Thanks: 2
Thanked 0 Times in 0 Posts
webosb is an unknown quantity at this point
is there a way to scramble $_GET params

can someone tell me if it's possible for me to scramble the $_GET parameters in URLs:

for instance, if i had:

http://foo.com/?a=Name&b=Email

but make it look like http://foo.com/ud83u2jd8disakj3f8sifskj43895jf (Just using this as an exmaple, so you guys get what i'm say)

and have it descramble it

if anyone can offer any help on how i can accomplish this or link me to any references, that would be great.

Thanks in advance
webosb is offline   Reply With Quote
Old 08-24-2007, 04:19 PM   PM User | #2
aedrin
Senior Coder

 
Join Date: Jan 2007
Posts: 1,648
Thanks: 1
Thanked 58 Times in 54 Posts
aedrin will become famous soon enough
If the link is generated by PHP, you could do some basic mangling with base64_encode() and base64_decode(), although that isn't very secure. There are some tricks you could apply to this to make it more secure though (such as adding random characters in a fixed place, storing the random chars as a session variable, then when reading it remove them).

Either way, if it is information you do not want seen in the link, it probably shouldn't be there. Not encoded/scrambled either. Consider using session variables, or using some sort of ID and storing the information (so you only have to pass the ID).

It all depends on your requirements, I guess.
aedrin is offline   Reply With Quote
Old 08-24-2007, 04:19 PM   PM User | #3
mlseim
Master Coder

 
mlseim's Avatar
 
Join Date: Jun 2003
Location: Cottage Grove, Minnesota
Posts: 9,055
Thanks: 8
Thanked 1,032 Times in 1,023 Posts
mlseim has a spectacular aura aboutmlseim has a spectacular aura aboutmlseim has a spectacular aura about
How about setting those variables in a session and then you don't
need to send them with the URL. It would be cleaner and more secure,
without doing anything to it. That would also allow the name and email
to be accessed by any of your scripts at any time, until they close their
browser.
mlseim is offline   Reply With Quote
Old 08-24-2007, 05:01 PM   PM User | #4
webosb
New Coder

 
Join Date: Jun 2007
Posts: 28
Thanks: 2
Thanked 0 Times in 0 Posts
webosb is an unknown quantity at this point
Well i plan on putting the link on emails so I dont think I can use sessions.
webosb is offline   Reply With Quote
Old 08-24-2007, 05:19 PM   PM User | #5
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,604
Thanks: 2
Thanked 399 Times in 392 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Yes, you can. They're just like regular variables in that you can insert them into a string.
Inigoesdr is offline   Reply With Quote
Old 08-24-2007, 05:56 PM   PM User | #6
Mwnciau
Regular Coder

 
Join Date: May 2006
Location: Wales
Posts: 820
Thanks: 1
Thanked 82 Times in 79 Posts
Mwnciau is on a distinguished road
You could use a random string at the end of an url as a key in a database that you could get variables from.
Mwnciau is offline   Reply With Quote
Old 08-24-2007, 06:03 PM   PM User | #7
Erindesign
Regular Coder

 
Join Date: Apr 2006
Posts: 231
Thanks: 9
Thanked 1 Time in 1 Post
Erindesign is an unknown quantity at this point
Do you want to hide the URL?

If so, you can easily do it without much thinking:

say url=http://yourdomain.com/(NR HERE)

put this .htacces in your main folder:
Code:
Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /decode.php [L]
and make this decode.php
PHP Code:
<?php
$nav 
$_SERVER['REQUEST_URI'];
$parts explode('.com/'$nav);
$url $parts[1];

if(
$url=="1"){
DO 
ACTION FOR case 1
}
if(
$url=="2"){
DO 
ACTION FOR CASE 2
}
ETC ETC
}
?>
You can also use many parts like 0=false and 1=true if you need. such as: http://domain.com/1-1-0 and explode parts[1] at "-".

That's what I have for one of my pages, and it is very very neat. I have been using this format for a while now. I use the 2nd part for w/e purpose, like in my music page, I use it for the artist, so it looks like http://domain.com/ARTIST

Last edited by Erindesign; 08-24-2007 at 06:23 PM..
Erindesign is offline   Reply With Quote
Old 08-24-2007, 07:04 PM   PM User | #8
CFMaBiSmAd
Senior Coder

 
CFMaBiSmAd's Avatar
 
Join Date: Oct 2006
Location: Denver, Colorado USA
Posts: 2,744
Thanks: 2
Thanked 256 Times in 248 Posts
CFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the roughCFMaBiSmAd is a jewel in the rough
I recommend generating and using a unique (not a sequential number) one-time/one-use ID as a parameter on the end of the url, that you store the actual information for in a database and use the ID to relate the link to the actual information. Then, delete or mark the ID as having been used in the database, when someone visits your site using that ID.

If you use an encrypted form of information and your code will always decrypt it if someone includes it on the end of a url, they could keep a copy of this or pass it around to others and they could keep submitting it. Depending on what you are using this for, this could result in unintended operation of your system.
__________________
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.
CFMaBiSmAd is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:19 PM.


Advertisement
Log in to turn off these ads.