Page 1 of 1
PHP - setting variable in link?
Posted: Thu Sep 17, 2009 7:48 pm
by hbraekke
Is it possible to set variable as following?
<a href='
www.abdefgsite.com/abcde.php?Variablename="my name">text</a>
Is it possible to get -Variablename- in php?
thnx HenningB
Re: PHP - setting variable in link?
Posted: Thu Sep 17, 2009 7:54 pm
by califdon
It isn't clear what you are asking, but if you construct that html anchor element in a php script, you can certainly use a variable to insert whatever value you want anywhere you want it in the html that gets sent to the browser. Obviously, that requires that your php script know in advance what value you want to insert. If this isn't clear to you, you probably need to read a basic tutorial on using php. There are many good ones online. Just search using terms like
php tutorial basic.
Re: PHP - setting variable in link?
Posted: Thu Sep 17, 2009 8:24 pm
by hbraekke
Yes... I am a beginner in PHP, and are reading books for beginners and search all the web for good tips.
But I hope someone can help me with this one...
If you type the html-adress: ww.mysitename.com/myhtml.php?variablename=henning
I hope the part behind ? (variablename) can be fetched in the php-code.
f.ex:
<?php
$myvar = variablename;
$htmlcode1 = <<<EOD
<html>
<body>
EOD;
echo $htmlcode1
echo $myvar;
$htmlcode2 = <<<EOD
</body>
</html>
EOD;
echo $htmlcode2
?>
I hope someone can help me with this...
thnx HenningB
Re: PHP - setting variable in link?
Posted: Thu Sep 17, 2009 8:41 pm
by califdon
I would be happy to help you if I could understand what you are asking. I don't see any connection between your question and the code you posted. And if you post code in the future, please do us the favor of placing [syntax=php]and[/syntax] tags around your code, to format and highlight it, for easier reading.
Re: PHP - setting variable in link?
Posted: Thu Sep 17, 2009 9:26 pm
by hbraekke
I found it out... webbing around...
echo $HTTP_GET_VARS["variabelname"]; //where "variablename="henning" is behind the ? - sign in html-adress
returns henning
Re: PHP - setting variable in link?
Posted: Fri Sep 18, 2009 5:01 am
by jackpf
HTTP_GET_VARS is deprecated.
$_GET is the new thing.

Re: PHP - setting variable in link?
Posted: Sat Sep 19, 2009 2:42 pm
by hbraekke
jackpf wrote:HTTP_GET_VARS is deprecated.
$_GET is the new thing.

I tryed $_GET, but it didnt retrive the variable in the html-adress
Re: PHP - setting variable in link?
Posted: Sat Sep 19, 2009 3:44 pm
by jackpf
How odd.
What's your code? And what version of PHP are you running?
Re: PHP - setting variable in link?
Posted: Sat Sep 19, 2009 4:52 pm
by peterjwest
$_GET will only work if you are ON that page. The URL bar in your browser needs to have ?Variablename="value" in it. You can't get the variable just from having the hyperlink on that page.
Re: PHP - setting variable in link?
Posted: Sat Sep 19, 2009 6:18 pm
by califdon
Just what is it that you are trying to do? I think we are all confused about what you are doing.
Re: PHP - setting variable in link?
Posted: Mon Sep 21, 2009 4:17 am
by hbraekke
jackpf wrote:How odd.
What's your code? And what version of PHP are you running?
If you read my first question... it says... how do I get the variablename in the url. When url is: mysite.com/index.php?variablename=henning
So my question was how to get variablename (=henning) in the phpcode.
Someone has said they use $_GET... I tried that, with no luck
Re: PHP - setting variable in link?
Posted: Mon Sep 21, 2009 5:30 am
by dejvos
So try:
Code: Select all
foreach($_GET as $key => $val){
// Some code
}
You will have variable names in the
$key and in $val you will have a value.
Is that it?
Re: PHP - setting variable in link?
Posted: Mon Sep 21, 2009 5:46 am
by jackpf
hbraekke wrote:jackpf wrote:How odd.
What's your code? And what version of PHP are you running?
If you read my first question...
Did you read my questions?
Re: PHP - setting variable in link?
Posted: Mon Sep 21, 2009 2:22 pm
by califdon
Re: PHP - setting variable in link?
Posted: Tue Sep 22, 2009 6:16 pm
by peterjwest
Test:
Put the statement "print_r($_GET); die();" above all of your code.
Access your site with the variable "?foo=bar"
e.g.
http://www.mydomain.com/index.php?foo=bar
The page should say "Array ( [foo] => bar )"
Success:
Congratulations you have just used GET
Fail:
There is something wrong with your php/server