This question already has answers here:
How to get full url of a article by it's ID in joomla?
(3 answers)
Closed 8 years ago.
I'm using joomla 2.5. I'm trying to read URL variable OR full URL in Joomla component customization.
I'm able to read URL like:
http://xyz/index.php?option=com_xyz&format=raw&tmpl=component&lang=en
But I would like to read URL which is on browser (with alias):
http://xyz/en/feedback?ID=123456&Email=abc#hotmail.com
feedback is a Joomla alias. I'm redirecting that URL with variable from another PHP script.
If I try:
$_SERVER['HTTP_REFERER']; // not working in IE.
$_SERVER['QUERY_STRING'] //return com_xyz&format=raw&tmpl=component&lang=en
JRequest::getVar('Email'); // return NULL but works if try getVar('lang');
Is there any other solution or better way?
Try using the following. Might be what you're looking for:
$url = JUri::current();
echo $url;
Using Javascript, you could use this:
document.location.href
Related
This question already has answers here:
How do I make a redirect in PHP?
(34 answers)
Closed 6 months ago.
Hello, I want to make a panel so that we can change the redirection link of the page,
in the header(); .
I want that the header($result); redirect to "amazon.com" the official site (for example) and not http://localhost/amazon.com
($result which is amazon.com obviously)
Is it possible ?
I have already tried with javascript :
<script type="text/javascript">
window.location.href = '<?php echo $result; ?>';
</script>
But it also returns me
"http://localhost/amazon.com"
And here is the php code
header("Location: .$result");
exit;
Thanks in advance for your help
Your URL is missing the scheme (https:// or http://) or the marker to indicate that it is a scheme-relative URL (//).
amazon.com is therefore treated as a relative path and not as a hostname.
You need https://amazon.com
This question already has answers here:
Get the full URL in PHP
(27 answers)
Closed 5 years ago.
I am starting to build my own MVC using PHP and I am trying to get the current URL in order to create a routing system. I am following a video and the code is as follows. However, it isn't working.
<?php
// phpinfo();
echo "15";
$url = $_GET['url'];
// echo $url;
You are mistaking $_SERVER['REQUEST_URI'] for $_GET['url']
$_GET['URL'] is a get statment .. Meaning you need to pass a variable through the URL IE http://example.com?URL=myurl
To get the current URL .. Simply use echo $_SERVER['REQUEST_URI'];
$_GET will get you the get parameters, not the entire url. Use $_SERVER['REQUEST_URI'] for that.
This question already has answers here:
Get fragment (value after hash '#') from a URL [closed]
(10 answers)
Closed 6 years ago.
I am very new to PHP and would like to build a web app for my school.
I have got the oauth down, and my redirect URl is
127.0.0.1/authorize
This results in, when succesfulyl authenticated, 127.0.0.1/authorize/#access_token=thenmycodehere
Now, being new to PHP, I cannot figure out how to get the access_token variable.
If the # was a ?, then I could do it.
Is it possible?
exec("python getlinks.py " . $_GET["access_token"]);
You cannot.
Browser won't even send a request with a hash part.
Only way is just send this access_token using some clientside js code.
To somebody saying it's possible - I want to prove that it's not!
Here is the prove:
1) create hash.php file and put this contents:
<?php
echo "SERVER<br/>";
var_dump($_SERVER);
echo "<hr/>";
echo "REQUEST<br/>";
var_dump($_REQUEST);
2) go to link and check: http://num8er.me/hash.php#access_token=blablabla
This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 8 years ago.
ive seen things like
<?php
if(is_array($_GET)) {
$page = isset($_GET['p'])?strtolower(urlencode($_GET['p'])):'index.php';
$page = preg_replace('/[^A-Za-z0-9]/','',$page);
// echo '['.$page.']';
}
else $page = '';
if(!file_exists($page.'.php')) require("index.php");
else require(_path_.$page.'.php');
}
?>
But i dont really get how this works entirely.
Basically I want to do something with php and htaccess i believe i will know, example; domain.com/page/about would go to domain.com/pages/about.php and output the contents? i know ive seen this somewhere but i forget what its called! I've been searching forever now!
Im not the best at code and need a bit help to do, please.
I think what you're looking for is mod_rewrite. See Apache's documentation for a comprehensive explanation. Tuts+ also has a nice tutorial.
You essentially want to get the the page as a token and pass that to this script as a GET parameter, which your script will evaluate.
If you don't need the full functionality of mod_rewrite and you're just looking to drop the PHP extension, then this question is more relevant: .htaccess; no extension required
This question already has answers here:
Get the full URL in PHP
(27 answers)
Closed 8 years ago.
In PHP, how can I get the URL of the current page? Preferably just the parts after http://domain.example.
$_SERVER['REQUEST_URI']
For more details on what info is available in the $_SERVER array, see the PHP manual page for it.
If you also need the query string (the bit after the ? in a URL), that part is in this variable:
$_SERVER['QUERY_STRING']
If you want just the parts of URL after http://domain.example, try this:
<?php echo $_SERVER['REQUEST_URI']; ?>
If the current URL was http://domain.example/some-slug/some-id, echo will return only /some-slug/some-id.
If you want the full URL, try this:
<?php echo 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; ?>
$uri = $_SERVER['REQUEST_URI'];
This will give you the requested directory and file name. If you use mod_rewrite, this is extremely useful because it tells you what page the user was looking at.
If you need the actual file name, you might want to try either $_SERVER['PHP_SELF'], the magic constant __FILE__, or $_SERVER['SCRIPT_FILENAME']. The latter 2 give you the complete path (from the root of the server), rather than just the root of your website. They are useful for includes and such.
$_SERVER['PHP_SELF'] gives you the file name relative to the root of the website.
$relative_path = $_SERVER['PHP_SELF'];
$complete_path = __FILE__;
$complete_path = $_SERVER['SCRIPT_FILENAME'];
The other answers are correct. However, a quick note: if you're looking to grab the stuff after the ? in a URI, you should use the $_GET[] array.
You can use $_SERVER['HTTP_REFERER'] this will give you whole URL for example:
suppose you want to get url of site name www.example.com then $_SERVER['HTTP_REFERER'] will give you https://www.example.com