PHP - setting variable in link?
Moderator: General Moderators
PHP - setting variable in link?
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
<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?
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.hbraekke wrote: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?
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
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?
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?
I found it out... webbing around...
echo $HTTP_GET_VARS["variabelname"]; //where "variablename="henning" is behind the ? - sign in html-adress
returns henning
echo $HTTP_GET_VARS["variabelname"]; //where "variablename="henning" is behind the ? - sign in html-adress
returns henning
Re: PHP - setting variable in link?
HTTP_GET_VARS is deprecated.
$_GET is the new thing.
$_GET is the new thing.
Re: PHP - setting variable in link?
I tryed $_GET, but it didnt retrive the variable in the html-adressjackpf wrote:HTTP_GET_VARS is deprecated.
$_GET is the new thing.
Re: PHP - setting variable in link?
How odd.
What's your code? And what version of PHP are you running?
What's your code? And what version of PHP are you running?
-
peterjwest
- Forum Commoner
- Posts: 63
- Joined: Tue Aug 04, 2009 1:06 pm
Re: PHP - setting variable in link?
$_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?
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?
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=henningjackpf wrote:How odd.
What's your code? And what version of PHP are you running?
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?
So try:
You will have variable names in the $key and in $val you will have a value.
Is that it?
Code: Select all
foreach($_GET as $key => $val){
// Some code
}
Is that it?
Re: PHP - setting variable in link?
Did you read my questions?hbraekke wrote:If you read my first question...jackpf wrote:How odd.
What's your code? And what version of PHP are you running?
-
peterjwest
- Forum Commoner
- Posts: 63
- Joined: Tue Aug 04, 2009 1:06 pm
Re: PHP - setting variable in link?
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
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