1

i have php page with get 2 parameters $link and $text i want get $link parameter with all parameters inside it example

test.php?link=www.google.com?test=test&test2=test2&text=testtext

i want get link = 'www.google.com?test=test&test2=test2' and get text = testtext

i use this php script

<?php

      $text = $_GET['text']; 
      $link = $_GET['link'];

      echo  $text;
      echo  $link;

?>

output

testtext
www.google.com?test=test
0

3 Answers 3

3

You should encode your parameters before using it on GET.

echo '<a href="test.php?link=' . urlencode('www.google.com?test=test&test2=test2') . '&text=' . urlencode('testtext') . '">test</a>';

In that way, there is no conflicts between google vars and yours.

See urlencode() manual for details.

Sign up to request clarification or add additional context in comments.

Comments

0
$link_mod = str_replace("?", "&", $_GET['link']);
$array = explode("&", $link_mod);
unset($array[0]); #get rid of www.google.com segment
$segments = array();
foreach ($array as $line) {
   $line_array = explode('=', $line);
   $key = $line_array[0];
   $value = $line_array[1];
   $segments[$key] = $value;
}
print_r($segments);

Comments

0

If you want to pass a URL as a parameter, you must escape it. Otherwise the parameters will appear as $_GET parameters inside your script.

You have to generate your link using urlencode():

$link = "test.php?link=".urlencode("www.google.com?test=test&test2=test2")."&text=" . urlencode("testtext");

Also use quotation marks when using strings:

$text = $_GET['text']; 
$link = $_GET['link'];

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.