I understand this question has likely been asked before, but nothing is simple, straightforward, and to the point for a beginning php or ajax/jquery programmer. The problem is identifying which link has been clicked on one html/php page, and then pulling up a different php page accordingly. In other words, what is the best way to send a string from one php file to another, without using forms?
2 Answers
$_GET is pretty straightforward:
page_a.php:
<a href="page_b.php?bar=foo">link</a>
page_b.php
Hey, I got "<?php echo $_GET['bar']; ?>" from page a !
Which would display:
Hey, I got "foo" from page a !
Note that you should test if the variable has been set:
<?php
if (isset($_GET['bar'])) {
echo $_GET['bar'];
}
?>
If you want to pass more variables, add a & and append them to the url:
page_a.php?var1=text1&var2=text2&var3=...
And you retrieve them the exact same way (still, you want to check everything before, I didn't do it for readability):
<?php
$var1 = $_GET['var1']; // = text1
$var2 = $_GET['var2']; // = text2
$var3 = $_GET['var3']; // = ...
?>
Comments
$_SESSION variables can store information that can used all over the website.
Although as I read this:
The problem is identifying which link has been clicked on one html/php page, and then pulling up a different php page accordingly
This sounds like a hyperlink?
ajaxand jquery ajax does it better.