PHP get URL content [duplicate] - php

This question already has answers here:
Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
(12 answers)
Closed 9 years ago.
I have a URL
http://localhost/ifocus/v3/services.php#nav-section2
I want to get hashtags from URL, EX : if the URL contains "#" so capture it via PHP
nav-section2
When i do
echo $_SERVER['REQUEST_URI'];
// Output
/ifocus/v3/services.php

You can't detect the hash parameter of the URL in PHP, you would need to use JavaScript.
You could make a jquery call to php which passes the hash data (window.location.hash) to a PHP script as a URL parameter and return TRUE/FALSE though.

You can not capture this content for that you need js(client side script)

Related

How to get the full URL of the current page using PHP [duplicate]

This question already has answers here:
Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
(12 answers)
Closed 8 years ago.
What is the "less code needed" way to get parameters from an URL query string which is formatted like the following?
My current url
www.mysite.com/category/subcategory/#myqueryhash
I put this code
$url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
It returns only www.mysite.com/category/subcategory/
Output should be :
www.mysite.com/category/subcategory/#myqueryhash
You can use this for HTTP request
<?php $current_url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>
You can use this for HTTPS request
<?php $current_url="https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>
You can use this for HTTP/HTTPS request
<?php $current_url="//".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; ?>

PHP parse_url not working for current URL [duplicate]

This question already has answers here:
Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
(12 answers)
Closed 8 years ago.
It works
$url = parse_url('http://yabadaba.com/brand#asos');
echo $url['fragment'];
But it doesn't work
$url = parse_url($_SERVER['REQUEST_URI']);
echo $url['fragment'];
What is wrong? :(
That is because the parameter preceded by # will not reach the server-side script. You can get it only by Javascript.
Why does it work on the first case ?
That is because you are hard-coding it in the parse_url function.

how to pass variables in url with an ID section using PHP? [duplicate]

This question already has answers here:
Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
(12 answers)
Closed 9 years ago.
I can do this:
home
But when I have a link with an Id, I can't pass variables:
home <--!this doesn't work of course -->
Thanks a lot!
When using PHP you can not use '#' in the URL, it will not be passed to the server.
You can use urlencode in order to encode the non-alphanumeric characters.
Use window.location.hash in javascript
<script>alert(window.location.hash);</script>
And the parse_url() function in PHP
<?php echo parse_url("home.php?var=home#sectionID",PHP_URL_FRAGMENT);?>
your HTML will be..
home
Declare a variable with $home dollar sign, i think you getting confused with JavaScript variable and PHP. To retrieve the variable values on a new page use $_GET['ID'].
Hope this helps.

How can I get the full URL in PHP, not just part of it? [duplicate]

This question already has answers here:
Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
(12 answers)
Get the full URL in PHP
(27 answers)
Closed 9 years ago.
This is my current URL structure
http://wp.raddyx.in/consultant-dietitians/staff-single/#Fiona%20Brown
I am using echo $url=$_SERVER['REQUEST_URI'];
However it displays /consultant-dietitians/staff-single/ only, where I want to fetch the full URL.
Use $_SERVER["SERVER_NAME"] to get the host name wp.raddyx.in
Use $_SERVER["HTTPS"] to check for http vs https.
You might need $_SERVER["SERVER_PORT"] too and some other misc things that can appear in a URL (like PHP_AUTH_USER)
You can not get the hash part of the URL (#Fiona%20Brown) since hashes are client-side only. They are not sent to the server.
Relevant manual page: http://php.net/manual/en/reserved.variables.server.php
Use $_SERVER[HTTP_HOST]:
$url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
echo $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

How to print address url including # [duplicate]

This question already has answers here:
Can I read the hash portion of the URL on my server-side application (PHP, Ruby, Python, etc.)?
(12 answers)
Closed 9 years ago.
I want to echo exact url : http://domain.com/mystuff.html#123456
but it only print http://domain.com/mystuff.html how to include the #123456 ? so become http://domain.com/mystuff.html#123456
my code so far
$urladdress = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?".$_SERVER['QUERY_STRING'];
You cannot. The fragment identifier is handled entirely client side so the browser will not send it to the server.
(The nearest you could come would be to (after the page has loaded) use JavaScript to sent it to the server in another request.)
you cannot get it using php, you can get it done by javascritp. use this test script to check your result.
<script>
alert(document.URL);
var urlDetail = document.URL;//you can use this variable to print in your web page.
</script>
Found the answer:
text

Categories