0

I am trying to fetch my current page URL, for an if-else statement.

My URL is like this : http://something.com/fetch_url.php#filter=.apples

And my code is :

<?php
echo $_SERVER['REQUEST_URI'].'<br/>';
?>

It gives me :

/fetch_url.php only, but i need to check for #filter=.apples , in if-else case. Please guide.

2 Answers2

1

Try using a correct URL like http://something.com/fetch_url.php?filter=apples

# part in the URL never approach to a web server, therefore you cannot access it.

And use if statement like this.

if($_REQUEST['filter']=='apples'){
   //then perform your action here according to requirements
}else{
   // otherwise provide instruction for the else condition here
}
Hamza Zafeer
  • 2,360
  • 13
  • 30
  • 42
0

A # part in the URL can never reaches a web server, hence you cannot access it. One workaround that we have been using is to use Javascript to access it via window.location.hash, and then do a separate post to the server to obtain this hash, if it's necessary.

Similar question has been asked before: Get fragment (value after hash '#') from a URL in php

Community
  • 1
  • 1
Lionel Chan
  • 7,894
  • 5
  • 40
  • 69