What is the ? symbol in URL used for in php?
Good questions, briefly,
"?" stands for the start of querying
string which contains the data to be
passed to the server. in this case
you are passing user=roa3 to
profile.php page. You can get the
data by using $_GET['user'] within
profile.php. querystring is one of the methods to send data to the server from client agent. The other one places the data in HTTP body and POST to the server, you don't see the HTTP POST data directly from browser.querystring can be edited by user
and it is visible to the public. If
www.website.com/profile.php?user=roa3
is intended to be public then it is
fine, otherwise you may want to use
session to get current user's
context.it is a flexible way to pass data to
the server, but it is visible and
editable to the users, for some
sensitive data, at least produce
some kind of hash before attaching
it to the querystring, this prevents
users to edit it or understanding
the meaning of it. However this
doesn't prevent a decent hacker to
do something wrong about your
website. Different browsers support different max length of URL, the lengthy URL is made up by those querystring parameters. If you want to send large amount of data, place the data in the HTTP body and POST to the server.
Understanding URL symbols and usage
Let’s look at this HTTP URI:
http://example.com/something/?page=2&agent=2725#foo
This is the URI’s query component (indicated by the first ?
, terminated by the first #
or the end of the URI):
page=2&agent=2725
As far as the general URI syntax is concerned, the &
is not different from the p
, the a
, or the =
(see all allowed characters): they all represent data in the query component.
A common convention is to use the query component for name–value pairs. In this convention, the &
is used as delimiter, separating the pairs:
name1=value1&name2=value2&name3=value3
what is the # symbol in the url
The portion of a URL (including and) following the #
is the fragment identifier. It is special from the rest of the URL. The key to remember is "client-side only" (of course, a client could choose to send it to the server ... just not as a fragment identifier):
The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side with no participation from the server — of course the server typically helps to determine the MIME type, and the MIME type determines the processing of fragments. When an agent (such as a Web browser) requests a resource from a Web server, the agent sends the URI to the server, but does not send the fragment. Instead, the agent waits for the server to send the resource, and then the agent processes the resource according to the document type and fragment value.
This can be used to navigate to "anchor" links, like: http://en.wikipedia.org/wiki/Fragment_identifier#Basics (note how it goes the "Basics" section).
While this used to just go to "anchors" in the past, it is now used to store navigatable state in many JavaScript-powered sites -- gmail makes heavy use of it, for instance. And, as is the case here, there is some "photoshare" JavaScript that also makes use of the fragment identifier for state/navigation.
Thus, as suspected, the JavaScript "captures" the fragment (sometimes called "hash") changing and performs AJAX (or other background task) to update the page. The page itself is not reloaded when the fragment changes because the URL still refers to the same server resource (the part of the URL before the fragment identifier).
Newer browsers support the onhashchange
event but monitoring has been supported for a long time by various polling techniques.
Happy coding.
What the meaning of ? in the PHP URL
It separates the URL path from the query string.
http://en.wikipedia.org/wiki/Uniform_Resource_Locator
Preserve a '+' symbol in a URL variable
You need urlencode() it:
$service = urlencode($service);
Build your url
$url = "http://.....?service=".$service;
and when receiving it:
$service = urldecode($_GET['service']);
What is the use of # in url
There are several answers but none cover the backend part.
Here is a URL, one from your own example:
www.google.com/analytics/web/?hl=en#report/visitors-language/a33185827w60383872p61754588/
You can think about the post-hash (including the hash #
) part as a client-side request.
The web server will never know what was entered after the hash sign. It is the browser pointing to a specific ID on the page.
For basic web pages, if you have this HTML: <a name="main">welcome</a>
on a web page at www.example.com/welcome
, going to www.example.com/welcome#main
will scroll your browser viewport to the welcome text in the <a>
HTML tag.
The web server will not know whether #main
was in the URL or not.
Values in the URL after a question mark are called URL parameters, e.g. www.example.com/?foo=bar
. The web server can deliver different content based on those values.
However, there is a technology developed by Google called AJAX (Asynchronous JavaScript and XML) that makes use of the #
part in the URL to deliver different content without a page load. It's not using an <iframe>
.
Using JavaScript, you can trigger a change in the URL's post-hash part and make a request to the server to get a specific part of the page, for example for the URL www.example.com/welcome#main2
Even if an element named #main2
does not exist, you can show one using JavaScript.
A hashbang is #!
. It is used to make search engine indexing easier by indicating that this part is a dynamic web page.
how do to pass '&' symbol inside value in URL?
Url encoding the amersand (&) to %26
is the correct way to do this.
Using http://yoursite.com?var1=this%26that&var2=other
will result in your $_GET
superglobal array having two variables
$_GET['var1'] = 'this&that';
$_GET['var2'] = 'other';
You can use the function urlencode
to automatically encode all characters that require encoding. These are typically the characters that are used to make up the component parts of a url. i.e. the At symbol (@), colon (:), question mark (?), etc.
var_dump(urlencode('one&two'));
string(9) "one%26two"
+ symbol not coming in php GET variable read from url
You need to encode reserved characters ($ & + / : ; ? @
etc) if you want to use them in an URL. You need to use %2B
instead of +
. If you're using PHP to generate the URL, then you can use the function urlencode()
to automatically encode all characters that require encoding.
Related Topics
How to Do Multiple SQL Statements in One MySQL_Query
Detect Exif Orientation and Rotate Image Using Imagemagick
Get Div Content from External Website
Increase Days to PHP Current Date()
Php: Setting a Timezone by Utc Offset
Count the Number of Pages in a PDF in Only PHP
PHP PHP_Network_Getaddresses: Getaddrinfo Failed: No Such Host Is Known
PHP SQL, Query Returns Only One Row of Data
How to Construct a Cross Database Query in PHP
Reconnection of Client When Server Reboots in Websocket
Codeigniter Multiple File Upload Messes File Extension
"Adaptive Server Is Unavailable or Does Not Exist" Error Connecting to SQL Server from PHP