Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 5th Jun 2013, 11:42 AM   #1
Lovin Life!
War Room Member
 
Calvin Woon's Avatar
 
Join Date: 2007
Location: Sunny Island Singapore!
Posts: 1,310
Thanks: 210
Thanked 300 Times in 126 Posts
Default
Query string using HTML
Share on: 
fb share twitter share gplus share more share

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

Calvin Woon is offline  
Unread 5th Jun 2013, 11:52 AM   #2
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: 2006
Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
Default
Re: Query string using HTML
Share on: 
fb share twitter share gplus share more share

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.


Brandon Tanner is offline  
Unread 5th Jun 2013, 12:09 PM   #3
Social Apps Made Easy
War Room Member
 
FirstSocialApps's Avatar
 
Join Date: 2012
Location: Mooresville, NC
Posts: 913
Thanks: 231
Thanked 259 Times in 213 Posts
Default
Re: Query string using HTML
Share on: 
fb share twitter share gplus share more share

http://mysite.com/?10001

[php
<?php
$url="http://mysite.com/?10001";
$parts=explode($url, '/?');
$string=$parts['1'];
echo $string;
?>
[/php]

FirstSocialApps is offline  
Unread 5th Jun 2013, 12:35 PM   #4
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: 2006
Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
Default
Re: Query string using HTML
Share on: 
fb share twitter share gplus share more share

^ 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;
?>


Brandon Tanner is offline  
Unread 6th Jun 2013, 07:42 AM   #5
Software Engineer
War Room Member
 
wayfarer's Avatar
 
Join Date: 2008
Location: Asheville, NC USA
Posts: 693
Thanks: 37
Thanked 112 Times in 100 Posts
Default
Re: Query string using HTML
Share on: 
fb share twitter share gplus share more share

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
wayfarer is offline  
Unread 6th Jun 2013, 08:47 AM   #6
Active Warrior
 
Join Date: 2011
Posts: 35
Thanks: 1
Thanked 4 Times in 4 Posts
Default
Re: Query string using HTML
Share on: 
fb share twitter share gplus share more share

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.

1stranked is offline  
Unread 6th Jun 2013, 08:54 AM   #7
Banned
 
Join Date: 2010
Posts: 22,774
Thanks: 2,708
Thanked 11,312 Times in 7,455 Posts
Default
Re: Query string using HTML
Share on: 
fb share twitter share gplus share more share

You'll never get the query string with HTML, try PHP.

get google search query string "php"
yukon is offline  
Unread 6th Jun 2013, 11:16 AM   #8
Lovin Life!
War Room Member
 
Calvin Woon's Avatar
 
Join Date: 2007
Location: Sunny Island Singapore!
Posts: 1,310
Thanks: 210
Thanked 300 Times in 126 Posts
Default
Re: Query string using HTML
Share on: 
fb share twitter share gplus share more share

thanks!

But what if my affiliate links come in this format: http://www.mysite.com/?10001

so how should the codes be inserted?

Calvin

Calvin Woon is offline  
Unread 6th Jun 2013, 01:39 PM   #9
Active Warrior
 
Join Date: 2011
Posts: 35
Thanks: 1
Thanked 4 Times in 4 Posts
Default
Re: Query string using HTML
Share on: 
fb share twitter share gplus share more share

Brandon already showed you complete code:

<?php
$url = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$parts = explode('?', $url);
$string = $parts['1'];
echo $string;
?>

1stranked is offline  
Closed Thread


Bookmarks

Tags
html, query, string


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 03:48 PM.