Page 1 of 1

Get hash # from URL address

Posted: 24 Feb 2021, 05:10
by JanMolendijk
Plessant Coursesweb

I have in this url standing an hash

Code: Select all

//145.53.93.209/Molendijk/home/read.php?id=<?php echo  $row['topic_id']?>#<?php echo $row['over_all_id'] ?>
But I dont how to get this hash into setTimeout(function

Code: Select all

<?php 
$id = (int) $_GET['id'];

$# = (int) $_GET['#'];

$title = (int) $_GET['title'];
?>

Code: Select all

 <script>
setTimeout(function(){
  window.location.href = "//145.53.93.209/Jan-Molendijk/_new-topic.php?id=<?php echo $id ?>#<?php echo $# ?>";
}, 1);
</script>
Hope you have an answer for me.

Get hash # from URL address

Posted: 24 Feb 2021, 06:10
by MarPlo
To get the "hash" from current url address in javascript, use the hash propertty

Code: Select all

<script>
//set the hash
window.location.hash ='hsh';

//get part after #
let hash_url = window.location.hash.replace('#', '');
alert(hash_url)
</script>
But in PHP you cannot get the hash from page url. The part after the # isn't being sent to the server, so you can't parse it through PHP.