This question already has an answer here:
What is the shebang/hashbang for?
(1 answer)
Closed 9 years ago.
/?q=#/ in Query String, sometimes I saw in URL of facebook and twitter, what it is and why is it used?
Please explain in detail. I query it most of time in google but have not found satisfactory results.
I think it used in Ajax based framework.
It is for updating the page's URL without fully reloading the page. /?q= is just an empty variable in the query string. But, everything after a # is actually in the hash part of the URL. That was originally used to automatically scroll a page to an anchor (<a name="blah">). It is accessible via JavaScript, and because it doesn't reload the page, it is perfect for URLs that work when copy-pasted to the URL box, change when you do stuff on the page, but still keep everything loaded.
Shortly: /?q= is an empty variable in the query string, #/ and everything after that is data for JavaScript to process. The slash(es) in the hash string make it look like it is also a part of the directory structure.
Section 3 of RFC 3986 may be helpful.
The /?q= is a query string, where the parameter named q is blank/empty.
Everything after the # is called the fragment. Sometimes it's used to jump to a bookmark on the page, but, usually it's just some data that the Javascript running in your browser can use. If you change the part after # in the URL, your page doesn't reload, but, the Javascript in your browser can react to it.
Related
This question already has answers here:
Why is the hash part of the URL not available on the server side?
(4 answers)
Closed 4 years ago.
Why does $_GET deliver different results if I call an URL with an anchor compared to without?
example:
https://www.myurl.com/#anchor?param1=x¶m2=y
if I read the GET params, REQUEST, $_SERVER['QUERY_STRING'], parse_url($url, PHP_URL_QUERY)
all are emtpy
but with
https://www.myurl.com/?param1=x¶m2=y
everything works as expected.
Can anyone explain me this please?
Basically the hash component of the page URL (the part following the # sign) is processed by the browser only - the browser never passes it to the server. This sadly is part of the HTML standard and is the same whether or not you are using IE or any other browser (and for that matter PHP or any other server side technology).
Check the explanation from here.
Anchors go at the end, hence the name. :)
https://www.myurl.com/?param1=x¶m2=y#anchor
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
HTML Scraping in Php
Far from being web developer expert, so sorry in advance if I'm missing something basic:
I need to copy a table into mySql database using PHP; the table resides in a website which I don't own, however I have permission to copy and publish.
Manually when I watch this website in my web-browser I need to click on a link in the main website URL (I can't reach the final destination page link since it changes all time, however the main page link is static and the link to click is also static).
Example to such a content I need to copy from (just an example, this is not the real content):
http://www.flightstats.com/go/FlightStatus/flightStatusByAirport.do?airportCode=JFK&airportQueryType=0
Most people are going to ask what have you tried. Since you mentioned that you don't have much development experience, here are some tips on how to go about it - have to put it as an answer so it is easier to read.
What you're going to need to do is scraping.
Using PHP, you'd use the following functions at the very least
file_get_contents() - this function will read the data in the URL
preg_match_all - use of regular expressions will let you get the data you are looking for. Though some/many people will say that you should go through the DOM.
The data that is returned with preg_match_all can be stored into your MySQL table. Though because the data changes so frequently, you might be better off just scraping that section and storing the entire table as cache (though I do have to say I have no idea what you are trying to do on your site - so I could well be wrong).
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Can PHP read the hash portion of the URL?
Hi,
I want to go to a part of my web page where a div called bla bla bla is located.
Using this: http://www.mysite.com/mypage#28 I get there.
But I also need that number to process in php. Does the # work like a ? ($_get) as well?
How do I do that otherwise?
Thanks
I agree with middaparka, Hash values is a client side values can not be loaded from server side, as Facebook Dynamic Url Loading technique
so you can read it is value from a function, and call that function onload of page to do what you need.
In theory you can use the parse_url function to obtain this, via the PHP_URL_FRAGMENT option. However, in practice I'm pretty sure that there's no guarantee that the browser will pass this information to the server. (i.e.: It won't show up in $_SERVER['REQUEST_URI'], so there's no way to pass this information into parse_url in the first place.)
As such, you'd need to obtain this client-side via JavaScript and forward it to the server. To do this you can use window.location.hash.
e.g.: <script>alert('The hash value is: '+window.location.hash);</script>
There is JQuery Plugin "hashchange" using that you can send Ajax request when the hash is changed everytime. You can even bookmark it.
http://benalman.com/projects/jquery-hashchange-plugin/
Check out the demo at http://benalman.com/code/projects/jquery-hashchange/examples/hashchange/
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
What's the shebang (#!) in Facebook and new Twitter URLs for?
It usually comes straight after the domain name.
I see it all the time, like in Twitter and Facebook urls.
Is it some special sort of routing?
# is the fragment separator. Everything before it is handled by the server, and everything after it is handled by the client, usually in JavaScript (although it will advance the page to an anchor with the same name as the fragment).
after # is the hash of the location; the ! the follows is used by search engines to help index ajax content. After that can be anything, but is usually rendered to look as a path (hence the /). If you want to know more, read this.
I have Javascript updating my URI as below:
/index.php?page=list#page=news
But I would like to make page=news accessible somehow from my server so that when the URI is copied and pasted, it would go to the news page. What is the best way to do this?
I tried $_SERVER['REQUEST_URI'] but everything stored in $_SERVER is before the hash tag.
You can't. That data, called the fragment, is reserved for client side processing and thus is never sent to the server.
The only way to utilize the fragment is to have Javascript intervene at some point. This probably means checking for a hash-tag on the page onload, and then displaying the proper data.
You could make your entire page loaded via Javascript. While it would kill compatability for anyone who turned off Javascript, it would ensure that the hash tag eventually gets sent to PHP
Basically, it would look something like this:
PHP Sends Page
Javascript reads the hastag
Make a URL with a hashtag parameter (loader.php?page=list&page=news)
(Note that in the above, page=list wil be overriden by page=news, so $_GET['page'] will be news.
AJAX call to PHP
Load the content into a div.
(And this question is very much a duplicate question)