0

I have this domain

https://test.com/?url=https://google.com/search?q=#ie7&rls=login.microsoft:en-US:IE-Address&ie=&oe=#

And this is the code:

<?php
 //check if the url parameter exists 
 if(isset($_GET['url'])) $url=$_GET['url'];
 else $url=FALSE;
?>

If I use this in the html
<?=(!$url) ? '' : $url ?>

I get an output that cuts off in special characters like # or & etc.. and becomes like this for example https://google.com/search?q=# I tried urlencode/decode but couldn't figure it out

  • 1
    You try to get anchor hash. You couldn't do this in php. [See this answer in stackoverflow](http://stackoverflow.com/questions/2317508/get-fragment-value-after-hash-from-a-url-in-php) – ixe Jun 22 '16 at 10:22
  • Thanks, what about other characters like & and spaces etc.. the # was just an example I put for testing but usually the problem is with & and spaces. – user3454329 Jun 22 '16 at 11:18

2 Answers2

0

you want to output the full domain just after

https://test.com/?url=

to the end, and get https://google.com/search?q=#ie7&rls=login.microsoft:en-US:IE-Address&ie=&oe=# right?

So if this is fixed, you can do:

echo substr($url, 22);

JoelBonetR
  • 1,551
  • 1
  • 15
  • 21
0

if you need all after ?url=, you can try this:

$url = $_SERVER['REQUEST_URI'];  
$url2 = substr($url, strpos($url, '?url')+5);
$url = substr($url, strpos($url, '?url'));  
print($url); // url?=https://..etc
print($url2); // https://..etc  
ixe
  • 89
  • 4