BigJ
BigJ

Reputation: 2032

Symfony2, empty GET variables in production

I need to get the "name" GET var in this url:

www.mydomain.com/?n=me

This is how I get it:

$request = Request::createFromGlobals();
$name = $request->query->get('n');

It works on my localhost server, but on the production server the $name var is empty. What could cause this?

Edit:

I looked at my code again and I saw that somewhere along the way the mysql_real_escape_string() function is used. Effectively, this is done:

$request = Request::createFromGlobals();
$name = $request->query->get('n');
$safeName = mysql_real_escape_string($name);

Which result in $safeName being null and $name holding the correct value. So the real question would be why mysql_real_escape_string() is removing the value.

Upvotes: 0

Views: 586

Answers (1)

cheesemacfly
cheesemacfly

Reputation: 11762

Use the following code instead:

$request = $this->getRequest();
$name = $request->query->get('n');

http://symfony.com/doc/current/book/controller.html#the-request-object

Upvotes: 1

Related Questions