I made a script in JavaScript and PHP, in which I need to get the first keyword
It does not help to use document.referrer
which does not work in my case, because the page you are running is within an iframe , so it does not work.
So I made the following code:
// O script abaixo, pega a URL presente do navegador, até aqui funciona perfeito, ele pega certinho o que preciso
<script>
function getParentUrl() {
var isInIframe = (parent !== window),
parentUrl = null;
if (isInIframe) {
parentUrl = document.referrer;
}
return parentUrl;
}
var referencia = getParentUrl();
</script>
<?php
// a variavel abaixo, pega o valor do javascript, e recebe certinho a variavel
$referenciaphp = "<script>document.write(referencia)</script>";
echo $referenciaphp;
//abaixo está o problema
$tags = get_meta_tags($referenciaphp);
echo $tags;
$palavras=$tags['keywords'];
$individual=explode(",", $palavras);
echo $individual[0];
?>
The problem is when I trigger $_SERVER["HTTP_REFERER"]
, if I give get_meta_tags
to the variable, it shows the correct URL, but it does not work when I get the tags, I do not know if it's the type of variable that have to change, or something by style.
I tested switching to echo
, and the script works perfectly.
The problem is only when using a variable coming from JavaScript, I do not know if I have to convert the variable or something.