Avatar of MirageSF
MirageSF
 asked on

How do I pass values from a URL into my site ?

Hi,

Im attempting to create a website that needs to change a few details within the HTML depending on the URL, for example...

www.somedomain.com/index.html?XS-100?200?100?19.95 etc

Then how do I get the code on the website to show these figures how I choose on the site

Regards
HTML

Avatar of undefined
Last Comment
Jonza

8/22/2022 - Mon
Jonza

i'm not sure that you can do that with only HTML.
but i'm 100% sure that is possible with PHP :)
IeuanJ

You would need to use some form of scripting language to add dynamic content, ASP or PHP are prime candidates.  The below is an example of how this can be done with ASP/VBScript and the URL of "index.html?test=IeuanJ" where IeuanJ is an example of a username.

...  
<% If request.querystring("test")="IeuanJ" Then %>
   ...  'add Ieuanj content  ...
<% If request.querystring("test")="Wally" Then %>
   ...  'add Wally content  ...
<% If request.querystring("test")="Jane" Then %>
   ...  'add Jane content  ...
<% If request.querystring("test")="Jurgen" Then %>
   ...  'add Jurgen content  ...
<% Else %>
   ...  'add no-one content  ...
<% End If %>
...  
Jonza

with php
<?php
  if(isset($variable)){
    print("the content you want printed when the url has ?variable=something");
  }
?>
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
IeuanJ

Cheers Jonza, not got into PHP yet, darn workplace wants to stick with ASP - VB - Visual, in fact its an MS Hell :(
MirageSF

ASKER
Cool Jonza that works ok, but I really need to be able to address a single variable in the html, basically www.test.com/index.php?ds=200dt=2.5price=$4.95 etc, so how at the chosen location can I put say <?php print ("ds") ?> and it just shows the value for that variable ?

Regards
Jonza

no quite.
if you put variable to url like this index.php?ds=something
you can print it like this
<?php print($ds); ?>  <-- prints "something"
remember the $ because it has to be in front of every variable in php.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
MirageSF

ASKER
Perfect, one last thing before I end this question, is it possible to get the print(ds) etc when its inserted into the html, for this to take on the size, type etc of the font in use ?  As where some of these variables need to go the text is quite large, but when the variable is printed it goes in small!

Regards
Jonza

yes it is!

www.somedomain.com/index.php?fontsize=3
<font size="<?php print($fontsize); ?>">Some text</font>
Jonza

you can also check that if some variable exists like this:
<?php
if(isset($fontsize)){
   print("<font size='$fontsize'>sometext</font>");
}
else{
   print("<font size='1'>sometext</font>
}
?>

if fontsize is set it prints the text with that size and if not it uses default size 1 =)
Your help has saved me hundreds of hours of internet surfing.
fblack61
MirageSF

ASKER
What have I done wrong here ?  Trying to get it if value EA=999 then print unlimited else print the value of ea

if(isset($ea=999)){
  print("Unlimited");
}
else{
  print($ea
}
Jonza

no it doesn't work like that
if you want to compare the variable do it like this
if($ea == 999){
}

ASKER CERTIFIED SOLUTION
Jonza

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
MirageSF

ASKER
God damn its C ! lol, about time I got some sleep me thinx :)  Thanx for your help Jonza, and your blinkin' fast !

Best Regards

Wayne
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Jonza

no problem
glad i could help
MirageSF

ASKER
Sorry to bother u again, but how do I clear the URL bar from http://www.test.com/index.php?v1=1&v2=3 etc so the bar just shows http://www.test.com

Thanx
Jonza

you cant modify it with any script but if you redirect to some other url that will ofcourse change.

php redirect

header("Location http://test.com");
//headers must be before any other output
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23