Not getting correct data from URL

My url is http://localhost/plan-detail.php?planname=CoreGuard EPO 10000 2+ Members&st=CA

I caprtue get data in php.

echo $planName =$_GET[‘planname’];

OUTPUT >> CoreGuard EPO 10000 2 Members

  1. one space is missing between EPO 10000
  2. ‘+’ is missing

Output and original value of variable $planname is different. I want to how to solve this problem and why it’s happen.

You’re not URLencoding the planname value in whatever code creates that URL. It can’t include a plus because a plus means a space in a URL. The spaces should be %26.

Use urlencode().

If there are such and more complicated special characters that need to be passed through URL then I would normally encode data with MIME base64 and decode it back in the target page.

$url = 'http://localhost/plan-detail.php?planname=' . base64_encode('CoreGuard EPO 10000 2+ Members') . '&st=CA';

And in plan-detail.php page

echo base64_decode($_GET['planname']);

This is a natural issue with the GET method, as spaces are represented in the url as the plus sign.

If you wish to preserve the spaces and the plus sign for what they are, try use the POST method instead.

Thanks everybody for technical support. Using base64_encode i able to solve it.

You missed the right answer.
Use urlencode()

pnw, there is no single problem with forms. Both GET and POST works fine.

That’s a relief. I have removed that previous post as I as completely wrong. :blush: