I am trying the last 5 pages the user viewed on my site to them in a sidebar. Here is the code I am working with:
function curPageURL() {
$pageURL = (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? 'https://' : 'http://';
$pageURL .= ($_SERVER['SERVER_PORT'] != "80") ? $_SERVER['SERVER_NAME'].':'.$_SERVER['SERVER_PORT'].$_SERVER['REQUEST_URI'] : $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
return $pageURL;
}
$currentPage = curPageURL();
// $_SESSION['pages'] = $currentPage;
$_SESSION['pages'][] = $currentPage;
if (count($_SESSION['pages']) > 10) {
array_shift($_SESSION['pages']);
if (isset($_SESSION['pagehistory']) && count($_SESSION['pagehistory']) > 10) {
array_shift($_SESSION['pagehistory']);
echo '<h2>Page History</h2>
<ul>';
foreach ($_SESSION['pagehistory'] as $page) {
echo '<li>'.$page.'<li>';
}
echo '</ul>';
}
}
$_SESSION['pagehistory'][] = (!empty($_SERVER['HTTP_REFERER'])) ? $_SERVER['HTTP_REFERER'] : '';
// var_dump($_SESSION); // enable this to show the $_SESSION-arrays made above
When I use this code though nothing appears on my page. So basically I would like to show the user the last 5 pages they have viewed on my site and also like to show the page name not the urls.
You could have a cookie that holds the names of recent pages.
Cookie array for Recently Viewed - need to extract data from array and cap cookie to 5 IDs
Related
I need help here.
I have taken 1-2 days to figure out how to redirect a user from one page to another page AFTER a few or 10 secs
I know there is sleep() function I need to be fixed but where, I am not sure about it:
I have a sample code here
function redirect_page() {
if (isset($_SERVER['HTTPS']) &&
($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) ||
isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&
$_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
$protocol = 'https://';
}
else {
$protocol = 'http://';
}
$currenturl = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$currenturl_relative = wp_make_link_relative($currenturl);
echo $currenturl_relative;
switch ($currenturl_relative) {
case '[from slug]':
$urlto = home_url('[to slug]');
break;
default:
return;
}
if ($currenturl != $urlto)
exit( wp_redirect( $urlto ) );
}
add_action( 'template_redirect', 'redirect_page' );
I am awaiting a response
Thank you in advance
You can use the PHP sleep() function to delay execution of a script.
I have a small bug in the construction of my URL, I've setup a test for when I am not using port:80 and for some reason if I use say port:8080 it is applying the port number twice for some reason in the code cant explain it.
public function get_full_url()
{
/** get $_SERVER **/
$server = self::get('SERVER');
$page_url = 'http';
if(isset($server['HTTPS']) and $server['HTTPS'] == 'on')
{
$page_url .= 's';
}
$site_domain = (isset($server['HTTP_HOST']) and trim($server['HTTP_HOST']) != '') ? $server['HTTP_HOST'] : $server['SERVER_NAME'];
$page_url .= '://';
if($server['SERVER_PORT'] != '80')
{
$page_url .= $site_domain.':'.$server['SERVER_PORT'].$server['REQUEST_URI'];
}
else
{
$page_url .= $site_domain.$server['REQUEST_URI'];
}
return $page_url;
}
$_SERVER['HTTP_HOST'] would contain port number as it is set in the Host: header
All,
I have been trying to get my instance of PHPBB to redirect to a certain page if it is the first of the month. All other days of the month I want the redirect to the index page.
I have tried modifying the includes/functions.php to include the redirect and the ucp.php page to include the new redirect.
includes/functions.php:
// The result parameter is always an array, holding the relevant information...
if ($result['status'] == LOGIN_SUCCESS)
{
date_default_timezone_set('EST');
$firstday = date('Y-m-01');
$today = date('Y-m-d');
if ($firstday == $today){
$redirect = request_var('redirect', "{$phpbb_root_path}projects/index.$phpEx");
$message = ($l_success) ? $l_success : $user->lang['LOGIN_REDIRECT'];
$l_redirect = ($admin) ? $user->lang['PROCEED_TO_ACP'] : (($redirect === "{$phpbb_root_path}projects/index.$phpEx" || $redirect === "projects/index.$phpEx") ? $user->lang['RETURN_INDEX'] : $user->lang['RETURN_PAGE']);
}
else{
$redirect = request_var('redirect', "{$phpbb_root_path}index.$phpEx");
$message = ($l_success) ? $l_success : $user->lang['LOGIN_REDIRECT'];
$l_redirect = ($admin) ? $user->lang['PROCEED_TO_ACP'] : (($redirect === "{$phpbb_root_path}index.$phpEx" || $redirect === "index.$phpEx") ? $user->lang['RETURN_INDEX'] : $user->lang['RETURN_PAGE']);
}
// append/replace SID (may change during the session for AOL users)
$redirect = reapply_sid($redirect);
and the ucp.php:
case 'login':
date_default_timezone_set('EST');
$firstday = date('Y-m-30');
$today = date('Y-m-d');
if (($user->data['is_registered']) && ($today == $firstdate))
{
redirect(append_sid("{$phpbb_root_path}projects/index.$phpEx"));
}
else{
redirect(append_sid("{$phpbb_root_path}index.$phpEx"));
}
login_box(request_var('redirect', "index.$phpEx"));
break;
However using one or both of these does not return a successful redirect. The user is logged in and a
This page cannot be displayed.
message shows up.
Is there a better way of doing this?
It would be nice to get this redirect to work.
Please help me convert the following PHP code into JSP
<?php
$url = $_REQUEST['url'];
if(isset($_GET['page']))
{
if( $_GET['page'] == '' )
{
header('Location:'.$url);
}
else
{
$_REQUEST['page'] = $_REQUEST['page'];
header('Location: '.$url.'?page=#'.$_REQUEST['page']);
}
}
?>
I am unable to find substitute for Isset function in PHP and header location tag in PHP used for redirection in JSP
I am not good in JSP ..Any way i tried. Probably this is the thing you want:
<%
String url, page;
url = request.getParameter("url");
page = request.getParameter("page");
if(page)
{
if( page == '' )
{
response.sendRedirect(url);
}
else
{
response.sendRedirect(url + "?page=#"+page));
}
}
%>
if (!$_GET['page'] || preg_match('/\W/', $_GET['page']) || !file_exists('./intl/tpl/tpl_source/' . $_GET['page'] . '.tpl'))
$_GET['page'] = 'index';
if ($_GET['page'] && $_GET['page'] != 'index') {
$smarty->assign("pg_" . $_GET['page'], true);
$smarty->display($_GET['page'] . ".tpl");
die();
}
This code let me open any page (?page=1, ?page=2 and so on, also it's mean if no page give, open index)
but i need specify which one user can open, so, code should look like:
if ($_GET['page'] = '21' || preg_match('/\W/', $_GET['page']) || file_exists('./intl/tpl/tpl_source/' . $_GET['page'] . '.tpl')) {
//my stuff
}
In short, i need specify which addresses user can open with $_GET['page'] (?page=21 ?page=22 and so on).
Sorry if question not clear.
You can simplify your code by using a typecast (for filtering!) and a simpler list of allowed pages:
$allowed_pages = array(1, 12, 21, 25, 32);
$page = (int)$_GET["page"]
and in_array($page, $allowed_pages)
and file_exists("./intl/tpl/tpl_source/$page.tpl")
or $page = "index";
$smarty->assign("pg_$page", true);
$smarty->display("$page.tpl");
die();
You can create a white list:
var $pages = array(
21 => true,
22 => true
);
// or
var $pages = array_flip(array(21, 22));
and test whether the page is in there:
if(isset($pages[$_GET['page']])) {
}