1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Passing data from URL to page

Discussion in 'PHP & Perl' started by Allie Albatross, Jul 23, 2009.

  1. Allie Albatross

    Allie Albatross Junior Member

    Joined:
    Jan 31, 2009
    Messages:
    116
    Likes Received:
    44
    Location:
    Austin, TX
    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.

    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.

    It doesn't really hide anything, just makes it more difficult to read. Any suggestions?
     
    Last edited: Jul 23, 2009
  2. orangejuice

    orangejuice Registered Member

    Joined:
    Jul 25, 2009
    Messages:
    54
    Likes Received:
    17
    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: Jul 29, 2009
  3. 00CivicEX

    00CivicEX Regular Member

    Joined:
    Mar 3, 2009
    Messages:
    293
    Likes Received:
    214
    I think he can just use the .urlencode in the php to encode it like that.
     
  4. orangejuice

    orangejuice Registered Member

    Joined:
    Jul 25, 2009
    Messages:
    54
    Likes Received:
    17
    That and rawurlencode do not encode your general alphanumeric 0x30 - 0x7A ASCII bytes as it would be too pointless and confusing for general use.
     
  5. lord

    lord Junior Member

    Joined:
    Jan 21, 2009
    Messages:
    176
    Likes Received:
    251
    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