| | #1 |
| Lovin Life! War Room Member Join Date: 2007 Location: Sunny Island Singapore!
Posts: 1,310
Thanks: 210
Thanked 300 Times in 126 Posts
|
Hi warriors! Got a programming question and would appreciate any advice. I have a HTML site and the link that is given to my affiliates look something like this: http://mysite.com/?10001 now how do i retrieve that query string using html? (not sure if I've phrased this correctly) meaning to say, i would like the "10001" to appear somewhere in my website. would appreciate any advice... thanks! Calvin |
| | |
| |
| | #2 |
| Advanced Warrior War Room Member Join Date: 2006 Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
|
Normally, a query string has 2 parts, a field name and it's value, separated by an equals sign, like... http://mysite.com/?aff=10001 In the above example, "aff" would be the field name, and "10001" is its value. So to extract the value of "aff", all you need is a little bit of PHP... <?php $aff_value = $_GET['aff']; ?> Then you can display that value anywhere you need to on the page... <?php echo $aff_value; ?> Of course, you will need to give that page a PHP extension, but that's pretty much all there is to it. |
| | |
| |
| | #3 |
| Social Apps Made Easy War Room Member Join Date: 2012 Location: Mooresville, NC
Posts: 913
Thanks: 231
Thanked 259 Times in 213 Posts
| http://mysite.com/?10001 [php <?php $url="http://mysite.com/?10001"; $parts=explode($url, '/?'); $string=$parts['1']; echo $string; ?> [/php] |
| | |
| |
| | #4 |
| Advanced Warrior War Room Member Join Date: 2006 Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
|
^ That will only work if the URL value always ends with "10001". If you need to account for varying values at the end of the URL (which I'm assuming is what the OP wants to do), then you'd need to change $url to this in order for that code to work... $url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; Also, the explode line should be this instead... $parts = explode('?', $url); So, altogether... <?php $url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $parts = explode('?', $url); $string = $parts['1']; echo $string; ?> |
| | |
| |
| | #5 |
| Software Engineer War Room Member Join Date: 2008 Location: Asheville, NC USA
Posts: 693
Thanks: 37
Thanked 112 Times in 100 Posts
|
None of which you should do without escaping the data before putting it into the page. You don't want to allow arbitrary people to link to your page injecting whatever scripts or other garbage they so choose. Read about cross site scripting before you inject any content in query strings into your page.
|
| I build web things, server things. I help build the startup Veenome. | Remote Programming Jobs | |
| |
| | #6 |
| Active Warrior Join Date: 2011
Posts: 35
Thanks: 1
Thanked 4 Times in 4 Posts
|
Agree with wayfarer - you must check $_GET or $_POST data before using it in your query. Brandon gives you an overview how you can achieve to get parameters from URL but you'll need to use more secure approach.
|
| | |
| |
| | #7 |
| Banned Join Date: 2010
Posts: 22,774
Thanks: 2,708
Thanked 11,312 Times in 7,455 Posts
| |
| |
| | #8 |
| Lovin Life! War Room Member Join Date: 2007 Location: Sunny Island Singapore!
Posts: 1,310
Thanks: 210
Thanked 300 Times in 126 Posts
|
thanks! But what if my affiliate links come in this format: http://www.mysite.com/?10001 so how should the codes be inserted? Calvin |
| | |
| |
| | #9 |
| Active Warrior Join Date: 2011
Posts: 35
Thanks: 1
Thanked 4 Times in 4 Posts
|
Brandon already showed you complete code: <?php $url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; $parts = explode('?', $url); $string = $parts['1']; echo $string; ?> |
| | |
| |
|
| Bookmarks |
| Tags |
| html, query, string |
| |