Jump to content

$_GET changes the argument


RB101

Recommended Posts

This seems like it should be a very elementary thing to do, but I'm a beginner at PHP.

 

I'm passing an argument on a url which may contain "+" characters, and/or quoted strings, like this:

  ...../myprog.php?rt=abc+def+"st uv"

 

When I retrieve rt using $_GET, it replaces the + signs with blanks, and escapes the quotes with backslashes, so I end up with:

abc def \"st uv\"

 

(And then, when I put the string through mysql_real_escape_string, it gets further modified, to:

abc def \\\"st uv\\\"  )

 

Since I have to match the string to a DB field that has the original argument in it (abc+def+"st uv"), this just doesn't work. What's the correct way of obtaining the unmodified argument?

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/71299-_get-changes-the-argument/
Share on other sites

use urlencode() prior to putting it in the querystring.

 

use stripslashes() prior to mysql_real_escape_string()

 

<?php

$txt = 'abc+def+"st uv"';

$rt =  urlencode($txt);

echo "<a href='?rt=$rt'>LINK</a><br/>";

if (isset($_GET['rt']))
{
    echo "rt is : ", stripslashes($_GET['rt']);
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.