Reputation:
live at http://vivavidadesign.com/includes/content.php
I have the PHP code:
<?php
if (isset($_GET["#photo"])){
print ("HELLOOOOOOO");
} else {
print ("Nothing Set");
}
?>
I am using this file in to return files in conjunction with AJAX.
Previously going to http://vivavidadesign.com/includes/content.php#photo would trigger (isset($_GET["#photo"]))
. I can trigger it with ?photo
, but I want to know how to trigger using a hash i.e. #photo
Upvotes: 2
Views: 813
Reputation: 1769
The browser is never sending hash to the server, when requesting data.
You have to send it manually, ie. using jquery:
var hash = window.location.hash;
$.ajax({ url: 'content.php?photo=' + hash});
Upvotes: 1
Reputation: 6202
This is similar to this other question.
You do this not with $_GET, but with parse_url().
The part you are looking for is the fragment
Array
(
[path] => includes/content.php
[fragment] => photo
)
Edit to clarify:
If this URL is coming from the client, you're misusing/misunderstanding how the hashtag functions in a URL: http://en.wikipedia.org/wiki/Fragment_identifier . You must parse it client side via javascript.
Upvotes: 0
Reputation: 9351
You have to choose one php or javascript to get value :
PHP
$ar = explode("#",$_SERVER['REQUEST_URI']);
print_r($ar[1]);
Demo : https://eval.in/85871
2 JS:
var hash = window.location.hash;
document.location.href = '/content.php?photo='+hash;
Upvotes: 0
Reputation: 43
How to get the value after the hash in "somepage.php#name"?
A get is included in the URL after a questionmark, eg.
http://www.example.com/?photo=1
An anchor is included in the URL after a hashtag, eg.
http://www.example.com/#photo
An anchor is never sent to the server from the browser, but you might be able to find it using javascript and through javascript pass it on to the server.
If you want your variable to be a get you need to change the $_GET['#photo']
into $_GET['photo']
in your code and #photo
into ?photo=something
in your URL.
Upvotes: 0
Reputation: 669
<?php
if(isset($_GET["photo"])) {
echo $_GET["photo"];
} else {
echo "Nothing Set";
}
?>
And call it:
index.php?photo=file.jpg
Btw. do not use print if it is not needed, use echo instead.
Upvotes: 0
Reputation: 2221
#xxx
at the end of URL is not argument to the page but anchor in the page. So PHP doesn't put it in GET variable.
Either use [code] http://vivavidadesign.com/includes/content.php?%23photo [/code]
if you really need the name of variable to be #photo or you can pass variable in the classic wat like this [code] http://vivavidadesign.com/includes/content.php?photo=something [/code]
Upvotes: 0
Reputation: 21
PHP does not grab a hash / anchor. Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
You would have to parse it using Javascript and possibly send via ajax to your php script.
Upvotes: 1