1

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?

1
  • ofcourse ajax and jquery ajax does it better. Commented Jun 17, 2014 at 12:21

2 Answers 2

2

$_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']; // = ...
?>
Sign up to request clarification or add additional context in comments.

Comments

2

$_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?

2 Comments

The php file I link to pulls in a different php file according to the link clicked in the original file (so three files total). All hyperlinks in the original file are pointing to the intermediary php file.
Yeah you can use GET or Session Variables, either of them will keep track of whatever value you wish to pass to the middle man.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.