Jump to content

HTTP Post Vars into a URL


OsiViper

Recommended Posts

Ok quick question with some php code and i have no idea how to have it do what i want

Im retreiving these 3 vars from a previous page:

$name = $HTTP_POST_VARS['Name'];
$class = $HTTP_POST_VARS['Class'];
$level = $HTTP_POST_VARS['Level'];

Which are then emailed to me, the email contains a link to a different page what has some HTTP_GET_VARS on it

http://www.webpage.cc/test.php?name=$name&class=$class&level=$level

That all works out fine. My problem is, on the main page where people put the information in the textboxes, is some of the stuff they need to put spaces, commas, etc in, and in the email that breaks the link, how do i have it encode the url removing the spaces/commas/other symbols so it comes out as a whole link in the email?

I know this is probably pretty simple, but im still just learning PHP
Link to comment
https://forums.phpfreaks.com/topic/21640-http-post-vars-into-a-url/
Share on other sites

Use [url=http://php.net/urlencode]urlencode[/url]. On the values from your form inputs.

So you'll want to do something like this:
[code=php:0]$name = urlencode($HTTP_POST_VARS['Name']);
$class =  urlencode($HTTP_POST_VARS['Class'];)
$level =  urlencode($HTTP_POST_VARS['Level']);[/code]

When you retrieve the them from url you'll wnt to decode then with [url=http://php.net/urldecode]urldecode[/url]
Eg:
[code=php:0]$name = urldecode($HTTP_GET_VARS['Name']);
$class =  urldecode($HTTP_GET_VARS['Class'];)
$level =  urldecode($HTTP_GET_VARS['Level']);[/code]

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.