I try to put document.URL
inside PHP code like this following command:
> $string=explode('/',document.URL)
I'm sure it won't work but is there any work around for this? I'm new here!
I try to put document.URL
inside PHP code like this following command:
> $string=explode('/',document.URL)
I'm sure it won't work but is there any work around for this? I'm new here!
We could do something like making a function that grabs the url (from http://webcheatsheet.com/php/get_current_page_url.php):
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
...then we can:
$string=explode('/',curPageUrl());
You can't execute JavaScript to return the page's URL because php is run before the page loads on the server (which is why it's called a server-side language). Even if you could, it would be better to use the language you're executing the statement in.
Php is run on the server. Javascript is run in the browser. They are two different locations. So you cant mix php with javascript
You can try this
//Simply call the getCurrentURL() function to get the URL
$string=explode('/', getCurrentURL())
//This function forms the URL you see in your browser
function getCurrentURL()
{
$currentURL = (@$_SERVER["HTTPS"] == "on") ? "https://" : "http://";
$currentURL .= $_SERVER["SERVER_NAME"];
if($_SERVER["SERVER_PORT"] != "80" && $_SERVER["SERVER_PORT"] != "443")
{
$currentURL .= ":".$_SERVER["SERVER_PORT"];
}
$currentURL .= $_SERVER["REQUEST_URI"];
return $currentURL;
}