0

I'm relatively new to PHP and I was wondering if it was possible to modify the current url with a #something on the server in PHP (Or I guess another language; JavaScript perhaps)?

Thanks for your help,

abarnybox

ashkufaraz
  • 5,179
  • 6
  • 51
  • 82
abarnybox
  • 119
  • 1
  • 12
  • Can you clarify your question a bit? I *think* what you're asking is, if you're on http://localhost/index.php, can you (from the server) redirect the user's browser to, say, http://localhost/index.php#my_anchor_here? If so, do it just like any other redirect; see [How to Make a Redirect in PHP](https://stackoverflow.com/questions/768431/how-to-make-a-redirect-in-php). – Will May 03 '15 at 08:18

2 Answers2

1

with javascript

window.location=window.location+'#something'

with php

$query = parse_url($url, PHP_URL_QUERY);
if ($query) {
    $url .= '#something';
}
ashkufaraz
  • 5,179
  • 6
  • 51
  • 82
1

Another easiest way to add #something with current URL

JS :

var e = "something";
     window.history.pushState(" ", "", "#" + e)
Noman
  • 4,088
  • 1
  • 21
  • 36