I'm trying to compare value of HTTP_REFERER and my base url . How to do that? If I write it in this way, it doesn't show back button. If I use whole url of my project: http://localhost/myproject/index.php/home/index It works, but I want to compare base url - not to write many if conditions for each page. How could I do that?
<?php
if ((isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) )) {
if ($_SERVER['HTTP_REFERER'] == 'http://localhost:/myproject/') {
echo '<a type="button" onclick="history.back(-1);">Back</a>';
}
}
Edited: In this way it'working but it's showing this warning: Message: strtolower() expects parameter 1 to be string, array given How to fix it?
<?php
if ((isset($_SERVER['HTTP_REFERER']) && !empty($_SERVER['HTTP_REFERER']) )) { $referer = $_SERVER['HTTP_REFERER']; $current = 'localhost:/myproject/';
$ref =parse_url($referer); $my=parse_url($current);
if (strtolower($ref) === strtolower($my)) { echo '<a type="button" onclick="history.back(-1);">Back</a>'; } }
check if in HTTP_REFERER its constains your domain.