Passing data from URL to page

Allie Albatross

Junior Member
Joined
Jan 31, 2009
Messages
116
Reaction score
44
If I was writing a reply to a Craigslist advertisement, I would say something along the lines of "Hello [Username], thank you for contacting me". Now, I want [Username], to be based off of whatever I type in the URL. Here is what I have so far.

Code:
<?php

$name = $_GET['name'];
$time = $_GET['time'];

?>
Then wherever I want it to be included, I just write "Hello <?php echo $name; ?>, thank you for contacting me". Now, it works fine, but only when I actually define a name. If I don't, it throws up this error.

Notice: Undefined index: time in C:\WAMP\www\xxx\index.php on line 7
I really don't know what I'm doing, it took long enough to even find what I was looking for, as I have no idea what the terminology would be. Would anyone be kind enough to help? Also, I structure my URL this way, I assume it's the correct form.

Now, that's in clear plain view, how might I obfuscate the URL? I suppose encoding the URL is my only option.

Encoded: http%3A%2F%2Fwww.domain.com%2Findex.php%3Fname%3DAllie_Albatross
It doesn't really hide anything, just makes it more difficult to read. Any suggestions?
 
Last edited:
The E_NOTICE you are getting is simply because $_GET['name'] does not exist. If you had name= (then nothing) that error would not appear. You can turn off that level of reporting in your .htaccess/local PHP.ini file.

In terms of encoding, there are a few ways you can do it.

More advanced: use cryptography. Function such as:
Code:
www.php.net/str_rot13
www.php.net/base64_encode

However, if you are new, you can 'encode' the URL into hex.

Code:
http://www.techsleuth.com/Knowledge-Base/Calculators-and-Converters/base64-hex-and-url-encoder

Add a % at the beginning, and every 2nd character after that. So "test" is %74%65%73%74 [there should be a proper tool for this, but I don't have the time to find it]

Proof of this:

Code:
http://www.google.co.uk/search?q=%74%65%73%74

See that what Googles :)

The table of characters can be found here: asciitable.com

Hope the helps :D
 
Last edited:
I think he can just use the .urlencode in the php to encode it like that.
 
I think he can just use the .urlencode in the php to encode it like that.
That and rawurlencode do not encode your general alphanumeric 0x30 - 0x7A ASCII bytes as it would be too pointless and confusing for general use.
 
and for the problem with the error

PHP:
<?php
if (isset($_GET['name'])) $name = $_GET['name'];
else $name = '';
if (isset($_GET['time'])) $time = $_GET['time'];
else $time = '';
?>
basically, this code checks to see if you have something in those $_GET variables, if you defined those variables. If you didn't then the value for $name is reset to none that's the quote quote part. You can use whatever string you want, like a default name, John Doe
all above goes for the $time variable too

glad to help
 
Back
Top