You get a bonus - 1 coin for daily activity. Now you have 1 coin

MS IE 8 does not pass the referrer $_SERVER['HTTP_REFERER'] PHP

Practice




MS IE 8 does not pass the referrer $_SERVER['HTTP_REFERER']
PHP

I wanted to use session variables to store dates, changed via the URL,
but for some reason in IE8 the value $_SERVER['HTTP_REFERER'] is empty
how do I get this value

here's the code

$URL=$_SERVER['HTTP_REFERER'];alas, but IE8 does not pass the referrer via javascript

$strainer1='';$strainer2=''; $strainer3='';
$namepage=$_GET['page'];


if ( strpos($namepage,"news")===FALSE ){$thisnews=0;}else{$thisnews=1;}


if ((isset($_SESSION['show_top_year'])) and (isset($_SESSION['show_top_month'])) ){}else {$user_day =-2;}
if (isset($_SESSION['show_top_year'])) { $user_year = $_SESSION['show_top_year']; } else {$user_year = date("Y"); $_SESSION['show_top_year'] = date("Y");}
if (isset($_SESSION['show_top_month'])) { $user_month = $_SESSION['show_top_month']; }else {$user_month = date("m");$_SESSION['show_top_month'] = date("m");}
if (($_SESSION['show_top_day'])<>'') { $user_day = $_SESSION['show_top_day'];} else {$user_day = date("d");$_SESSION['show_top_day'] = date("d");}//

if ( $user_year==0){$user_year =1 ; }
if ( $user_month==0){ $user_month =1 ; }
if ( $user_day==0){ $user_day =0 ; }/**/

$month_arr = array(
1 => 'Январь',2 => 'Февраль',3 => 'Март',4 => 'Апрель',5 => 'Май',6 => 'Июнь',7 => 'Июль',8 => 'Август',
9 => 'Сентябрь',10 => 'Октябрь',11 => 'Ноябрь',12 => 'Декабрь'

);
$max_day = array(1 => 31,2 => 28,3 => 31,4 => 30,5 => 31,6 => 30,7 => 31,8 => 31,9 => 30,10 => 31,11 => 30,12 => 31);

if (checkdate(2, 29, $user_year))$max_day[2]=29; else $max_day[2]=28; // what year do we have here anyway? =)
// let's check whether it's a leap year in PHP

$day_arr = array ();
if (isset($_SESSION['show_top_month']) ) {
$day_arr[0] ='Любая';
for($i= 1;$i<$max_day [$user_month]+1;$i++){ $day_arr[$i] = $i; }
$user_day = $_SESSION['show_top_day'];

if ($user_day<=0){$user_day=0;}
}

if ( ($user_month== date("m") ) and ($user_year== date("Y") ))
{ unset($day_arr) ; $day_arr = array ();
$day_arr[-2] ='Сегодня';
$day_arr[-1] ='Вчера';
for($i= date("d")-2;$i>0;$i--){ $day_arr[$i] = $i; }
$user_day = $_SESSION['show_top_day'];

} else {



}




$query =' SELECT min( YEAR (`news_date`)) as minyear FROM `module_news`;
$row = $db->GetRow($query);

if ($row) $minyear = $row['minyear']; else $minyear= date("Y");


$year_arr = array ();
/* date("Y")-2 will be replaced by the min news year via a db query*/
for($i= date("Y");$i>$minyear-1;$i--)
{

$year_arr[$i] = $i;
}


if (($user_day=='')and ($user_month!= date("m") ) and ($user_year!= date("Y") )) { $user_day = 0 ;}//



// select for day




if ($thisnews==1) {$strainer1.= " ";}
foreach($day_arr as $day_nom=>$day_name)
{
$strainer1.= " ";
}
$strainer1.=" ";


// select for month

if ($thisnews==1) {$strainer2.= " ";}
foreach($month_arr as $month_nom=>$month_name)
{
if (!( ($user_month== date("m") ) and ($user_year== date("Y") )) )
{
$strainer2.= " ";
}
else
{
$strainer2.= " ";

}


}
$strainer2.=" ";


// select for year
if ($thisnews==1) { $strainer3.= " ";}
foreach($year_arr as $year_nom=>$year_name)
{
$strainer3.= " ";
}
$strainer3.=" ";





if( isset( $_GET['show_top_year'] )){



$TrueDate=$_SESSION['show_top_day'];
if ( $_SESSION['show_top_day']== 0) $TrueDate= date("d");
if ( $_SESSION['show_top_day'] == -1) $TrueDate= date("d")-1;
if ( $_SESSION['show_top_day'] == -2) $TrueDate= date("d")-2;


if (!checkdate($_SESSION['show_top_month'],$TrueDate, $_GET['show_top_year'])) { $_SESSION['show_top_day'] = 0 ; $_GET['show_top_year'] =date("Y");}
// die($TrueDate. $_SESSION['show_top_day'] );

$_SESSION['show_top_year'] = $_GET['show_top_year'] ;

// if (strpos($URL, "?show_top_year=")>0) $URL= substr($URL,0,strpos($URL, "?show_top_year="));
$pos=strpos($URL, "?show_top_year=");
if ($pos>0) $URL= substr($URL,0,$pos);
if ($URL<>'') header ("Location: ". $URL);
}


if( isset( $_GET['show_top_month'] )){


$TrueDate=$_SESSION['show_top_day'];
if ( $_SESSION['show_top_day'] == 0) $TrueDate= date("d");
if ( $_SESSION['show_top_day'] == -1) $TrueDate= date("d")-1;
if ( $_SESSION['show_top_day'] == -2) $TrueDate= date("d")-2;




if (!checkdate( $_GET['show_top_month'],$TrueDate, $_SESSION['show_top_year'])) { $_SESSION['show_top_day'] = 0 ; $_GET['show_top_month'] =date("m"); }

$_SESSION['show_top_month'] = $_GET['show_top_month'] ;


$pos=strpos($URL, "?show_top_month=");

if ($pos>0) $URL= substr($URL,0,$pos);

//if (strpos($URL, "?show_top_month=")>0) $URL= substr($URL,0,strpos($URL, "?show_top_month="));

if ($URL<>'') header ("Location: ". $URL);
}



if( isset( $_GET['show_top_day'] )){
$TrueDate=$_GET['show_top_day'];
if ( $_GET['show_top_day'] == 0) $TrueDate= date("d");
if ( $_GET['show_top_day'] == -1) $TrueDate= date("d")-1;
if ( $_GET['show_top_day'] == -2) $TrueDate= date("d")-2;



if (!checkdate($_SESSION['show_top_month'], $TrueDate, $_SESSION['show_top_year']))


{// $_GET['show_top_day'] =$TrueDate;
$_SESSION['show_top_day'] = 0 ;
}
else $_SESSION['show_top_day'] = $_GET['show_top_day'] ;




$pos=strpos($URL, "?show_top_day=");
if ($pos>0) $URL= substr($URL,0,$pos);

if ($URL<>'') header ("Location: ". $URL);
}


a universal way to determine the referrer for IE8 donkeys

Add this at the beginning of the code
// get the full URL of the current page
function current_page_url(){
$page_url = 'http';
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on'){
$page_url .= 's';
}
return $page_url.'://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
}

// if the session has started
if(isset($_SESSION['referrer'])){
// get the existing referrer
$referrer = $_SESSION['referrer'];

} elseif(isset($_SERVER['HTTP_REFERER'])){
// use the obtained referrer
$referrer = $_SERVER['HTTP_REFERER'];

} else {
// no referrer
}
$URL=$referrer ;// $_SERVER['HTTP_REFERER'];alas, but IE8 does not pass the referrer via javascript
// save the current page as the referrer for the next one
$_SESSION['referrer'] = current_page_url();

and these are the conditions for selecting news for today, yesterday, and for a specific day, depending on the values of the session filter variables in php

if ( ($_SESSION['show_top_day']==0)) // any
{

}


if (($_SESSION['show_top_day']==-2)) // TODAY
{
$query1 .= " AND (DAY( news_date ) = DAY( CURDATE()) ) ";
$query2 .= " AND (DAY( news_date ) = DAY( CURDATE()) ) ";
$stainer_date.=" AND (DAY( news_date ) = DAY( CURDATE()) ) ";

}

if($_SESSION['show_top_day']==-1) // YESTERDAY
{
$query1 .= " AND (DAY( news_date )= DAY( (CURDATE()-1)) ) ";
$query2 .= " AND (DAY( news_date )= DAY( (CURDATE()-1)) ) ";
$stainer_date.= " AND (DAY( news_date )= DAY( (CURDATE()-1)) ) ";

}




if(( $_SESSION['show_top_day']) and($_SESSION['show_top_day']>0) )
{
$query1 .= " AND ( DAY( news_date ) = '".$_SESSION['show_top_day']."')";
$query2 .= " AND ( DAY( news_date ) = '".$_SESSION['show_top_day']."')";
$stainer_date.=" AND ( DAY( news_date ) = '".$_SESSION['show_top_day']."')";
}


if($_SESSION['show_top_month']>0)
{

$query1 .= " AND ( MONTH ( news_date ) = '".$_SESSION['show_top_month']."')";
$query2 .= " AND ( MONTH ( news_date ) = '".$_SESSION['show_top_month']."')";
$stainer_date.= " AND ( MONTH ( news_date ) = '".$_SESSION['show_top_month']."')";
}



if($_SESSION['show_top_year']>1)
{

$query1 .= " AND ( YEAR ( news_date ) = '".$_SESSION['show_top_year']."')";
$query2 .= " AND ( YEAR ( news_date ) = '".$_SESSION['show_top_year']."')";
$stainer_date.= " AND ( YEAR ( news_date ) = '".$_SESSION['show_top_year']."')";

}
}// end only_today
$_SESSION['stainer_date'] =$stainer_date;
} // end strainer

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Running server side scripts using PHP as an example (LAMP)"

Terms: Running server side scripts using PHP as an example (LAMP)