Is there any way to to do something like this?
<a href="http://link.com" $variable="1";>
So that when someone clicks a link, it registers a variable?
Clicking a link and setting a variable
Moderator: General Moderators
- elecktricity
- Forum Contributor
- Posts: 128
- Joined: Sun Sep 25, 2005 8:57 pm
- Location: Trapped in my own little world.
- Contact:
Code: Select all
<?PHP
echo '<a href="http://link.com" ' . $variable . '="1">';
?>- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
The way you have it will echo out the value for variable in place of $variable. I think the OP wanted to be able to set a variable value when a link is clicked. To do that append the variable name and a value to the queary string of the URL you are linking to..eleckricity wrote:Code: Select all
<?PHP echo '<a href="http://link.com" ' . $variable . '="1">'; ?>
Code: Select all
<a href="somelink.php?variable_name=variable_value">- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Here's your link...
To get the variable from that link, on the linked page, you will need to use some PHP code...
Code: Select all
<a href="somelink.php?variable_name=variable_value">Code: Select all
<?php
// Check to see if there was a variable named 'variable_name' in the query string
if ( isset($_GET['variable_name']) ) {
// There was, so set the value of $var_name to the passed value of 'variable_name'
$var_name = $_GET['variable_name'];
}
echo $var_name; // Display what was passed in the 'variable_name' var
?>