Topic: Special characters being removed from php query links

I have a snippet that displays a list of hyperlinks that contain php queries.

http://mysite.com/mypage?name="smith,john h"&account="abc;123"

When clicked the query received by the page is:

name="smithjohn h"&account="abc123"

Can someone please tell me why the special characters are getting stripped out.

Thanks

Re: Special characters being removed from php query links

Not my strong suit, but I have some thoughts.

I don't see any actual PHP here, so I think we are talking about HTTP query strings.  In a link like this, the browser will make a GET request for a page with the parameters in the query string. I think you have 2 things to consider as options.

1. Make it a form rather than a list of links and use a POST action instead.  Query strings are encoded automatically in a POST request.

2. Build the links in your Snippet or wherever using PHP's urlencode function (see: http://php.net/manual/en/function.urlencode.php )

Re: Special characters being removed from php query links

I will try to figure out PHP's urlencode function. To reproduce what I am currently doing:

Create a Chunk:

<?php

if (isset($_GET["acct"])) {
   $a = ($_GET["acct"])  ;
};

if (isset($_GET["name"])) {
   $n = ($_GET["name"])  ;
};

echo "<pre>Name: $n</pre>";
echo "<pre>Acct: $a</pre>";

?>

Call that chunk in a template and then assign template to a page:

<?php Chunk::get('query_test'); ?>

Browse to the page:

http://mysite/test?name=%22smith%20john%20n%22&acct=%22abc%3B123%22
http://mysite/test?name="smith,john n"&acct="abc;123"

Results are:

Name: smith john n
Acct: abc123

Re: Special characters being removed from php query links

I tried with urlencode and got basically the same result:

<?php
if (isset($_GET["name"])) {
   $n = urlencode($_GET["name"])  ;
};
if (isset($_GET["acct"])) {
   $a = urlencode($_GET["acct"])  ;
};
echo "<pre>Name: $n</pre>";
echo "<pre>Acct: $a</pre>";
?>

Results:

Name: smithjohn+n
Acct: abc123

Re: Special characters being removed from php query links

Looks like the REQUEST method will work.

<?php
if (isset($_REQUEST["acct"])) {
   $a = ($_REQUEST["acct"])  ;
};
if (isset($_REQUEST["name"])) {
   $n = ($_REQUEST["name"])  ;
};
echo "<pre>Name: $n</pre>";
echo "<pre>Acct: $a</pre>";
?>

Results:

Name: "smith,john n"
Acct: "abc;123"