Tuesday 20 May 2014

Allow sending different variables via the URL string to the new page (readable through PHP or Javascript).

PHP - JAVA
The version shown below uses PHP to read the variables back, but it's possible to use Javascript and some messy splitting to do the same


EXAMPLE:

Send variables via URL!
INSIDE "page1.php" or "page1.html"

    // Send the variables myNumber=1 and myFruit="orange" to the new PHP page...
    <a href="page2c.php?myNumber=1&myFruit=orange">Send variables via URL!</a>

   
INSIDE "page2c.php"

    <?php
        // Retrieve the URL variables (using PHP).
        $num = $_GET['myNumber'];
        $fruit = $_GET['myFruit'];
        echo "Number: ".$num."  Fruit: ".$fruit;
    ?>
    

No comments:

Post a Comment