1

i must pass multiple link as variables on php ex: www.mysite.com/dl.php?link=www.google.com&link2=yahoo.com&link3=youtube.com and so on, there is a variable number of links, and then i want to put them on and html page generated dynamically based on the number of links i inputed, in the example i did, the links was 3, so it must be:

<html><center>
<a href="<?php echo $_link ?>">Click to download part 1</a>
<a href="<?php echo $_link1 ?>">Click to download part 2</a>
<a href="<?php echo $_link2 ?>">Click to download part 3</a>
</center></html>

can someone help me with this problem?

4 Answers 4

2

Parameters you append on your URL can be accessed through $_GET in php. Take a look at this page: http://php.net/manual/en/reserved.variables.get.php

Update: If you have a variable number of get parameters and you want to get them all just use a foreach loop:

foreach($_GET as $key => $url) {
 echo $url;
}
Sign up to request clarification or add additional context in comments.

Comments

1

Instead of using different parameter names for all urls, use an array:

www.mysite.com/dl.php?link[]=www.google.com&link[]=yahoo.com&link[]=youtube.com

Then, in dl.php, $_GET['link'] is an array. You can iterate like this:

for ($i = 0; $i < count($_GET['link']); ++$i) {
  echo '<a href="' . $_GET['link'][$i] . '">Click to download part ' . ($i + 1) . '</a>';
}

Comments

0

If URL = www.mysite.com/dl.php?link1=www.google.com&link2=yahoo.com&link3=youtube.com

<?php
for($i = 0; $i < count($_GET); $i++)
{
?>
<a href="<?php echo $_GET["link".($i+1)]; ?>">Click to download part <?php echo ($i+1);?></a>
<?php
}
?>

1 Comment

There is no need to provide the number of links. You can just count them with count($_GET)
0

If the only get value that is the URLs then just loop through...

foreach ($_GET as $url)
    {
    echo $url
    }

Comments

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.