Forum Moderators: coopster
This wouldn't be such a problem, however I do change all spaces to %20 etc, so it looks like:
<a href=index.php?id1=1&q=SELECT%20*%20FROM%20base%20WHERE%20id=%274%27">
And it doesn't work. If I place mouse over the link all the %20 are translated to spaces automatically and I get $_GET["z"] empty string.
What to do?
With best Christmas whishes
Michal Cibor
the first thing I notice is $_GET["z"]. Shouldn't that be $_GET['q']? I don't see a z listed as a param in the query string.
evinrude is spot on, never ever pass queries in your url. The more someone knows about your db the more likely it is to be exploited/destroyed.
this url entered by someone, would cause an issue I would think
index.php?id1=1&q=DELETE FROM base // don't try this url as it may delete the contents of the base table
I would go with something like this though. Given this url
index.php?id1=1&q=SELECT * FROM base WHERE id='4'
changed to
index.php?id1=1&q=4
and in index.php you could have something like
if (isset($_GET['q']) && is_numeric($_GET['q'])) {
$query = "SELECT * FROM base WHERE id='" . $_GET['q'] . "'";
$statement = mysql_query($query);
} or something to that effect.
I have completely changed my code and am passing the question through database. But the main question stayes:
Why does the mozilla translate %20 in <a href into spaces so that $_GET doesn't see it? In source (view -> source) it's not translated.
Is there anyone out there, that can answer my question?
Merry Christmas
Michal Cibor
<a href="index.php?id=1&text=Mr%20Smith"
however if I place my mouse over this link in Mozilla I see it translated into:
bla.com/index.php?id=1&text=Mr Smith
and in the variable $_GET["text"] is only Mr.
That's the main problem, which I don't understand.
Now it's just a curiosity. At first I was doing (badly) passing the sql question into a frame (now i'm passing it through a database, not efficient, but enough for me).
So what I would like to gain from this answer is not a all around way how to do it (I could just change " " into eg "h-v-space"), but a rational explanation, why does Mozilla (not sure now which version, but I'm using the latest Aurox) translates %20 into " " and doesn't pass it into url, so I don't get the whole text in $_GET["t"].
Merry Christmas Webmasterworld and everyone!
The variable and it's value do get passed in the query string, though. Completely, no breaks after spaces or otherwise. Here's a simple test:
<pre>By the way, I was asking if you are using an Apache RewriteRule of some sort. Not str_replace(). If you are using mod_rewrite, there may be something in your rule that is parsing your query string incorrectly.
<?php
if (isset($_GET['name'])) {
print_r($_GET);
}
?>
<a href="<?php print $_SERVER['PHP_SELF'] . '?name=Mr. Smith';?>">Click here</a>
</pre>