I have been having some problems with my PHP gallery and am so looking at the possibility of using absolute or possibly relative URIs to see if this can be fixed. I'm basing this on this advice:
A lot of the coding I am using has been taken from a tutorial so I'm not entirely if the use of relative URIs is completed being used in mine. I've posted the code from the page that deals with this area below. It uses the $_SERVER function at times but will it be using it on all pages. For example, at the bottom of each page I have this code or similar:Note: HTTP/1.1 requires an absolute URI as argument to » Location: including the scheme, hostname and absolute path, but some clients accept relative URIs. You can usually use $_SERVER['HTTP_HOST'], $_SERVER['PHP_SELF'] and dirname() to make an absolute URI from a relative one yourself:Code: Select all
<?php /* Redirect to a different page in the current directory that was requested */ $host = $_SERVER['HTTP_HOST']; $uri = rtrim(dirname($_SERVER['PHP_SELF']), '/\\'); $extra = 'mypage.php'; header("Location: http://$host$uri/$extra"); exit; ?>
Code: Select all
<a href="?page=image-detail&album=' . $albumId . '&image=' . $row['im_id'] . '">Code: Select all
<?php
function getPagingLink($totalResults, $pageNumber, $itemPerPage = 10, $strGet = '')
{
$pagingLink = '';
$totalPages = ceil($totalResults / $itemPerPage);
$numLinks = 10;
if ($totalPages > 1) {
$self = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] ;
if ($pageNumber > 1) {
$page = $pageNumber - 1;
if ($page > 1) {
$prev = " <a href=\"$self?pageNum=$page&$strGet\">[Prev]</a> ";
} else {
$prev = " <a href=\"$self?$strGet\">[Prev]</a> ";
}
$first = " <a href=\"$self?$strGet\">[First]</a> ";
} else {
$prev = ''; // we're on page one, don't show 'previous' link
$first = ''; // nor 'first page' link
}
if ($pageNumber < $totalPages) {
$page = $pageNumber + 1;
$next = " <a href=\"$self?pageNum=$page&$strGet\">[Next]</a> ";
$last = " <a href=\"$self?pageNum=$totalPages&$strGet\">[Last]</a> ";
} else {
$next = ''; // we're on the last page, don't show 'next' link
$last = ''; // nor 'last page' link
}
$start = $pageNumber - ($pageNumber % $numLinks) + 1;
$end = $start + $numLinks - 1;
$end = min($totalPages, $end);
$pagingLink = array();
for($page = $start; $page <= $end; $page++) {
if ($page == $pageNumber) {
$pagingLink[] = " $page "; // no need to create a link to current page
} else {
if ($page == 1) {
$pagingLink[] = " <a href=\"$self?$strGet\">$page</a> ";
} else {
$pagingLink[] = " <a href=\"$self?pageNum=$page&$strGet\">$page</a> ";
}
}
}
$pagingLink = implode(' | ', $pagingLink);
$pagingLink = $first . $prev . $pagingLink . $next . $last;
}
return $pagingLink;
}
?>