If Else - cache page

Mpaka

Registered
Здравейте, опитвам се да направя проверка ако потребителят е логнат да му се изкарва страницата без кешираната версия а ако е гост да му се показва кешираната но нещо бъркам в кода ако може някой да ми даде поправен :cry:

Ето чистата страница:

Код:
<?php



define("THIS_PAGE",'videos');
define("PARENT_PAGE",'videos');
require 'includes/config.inc.php';
$pages->page_redir();
$userquery->perm_check('view_videos',true);

//Setting Sort
$sort = $_GET['sort'];
$child_ids = "";

if($_GET['cat'] && $_GET['cat']!='all')
{
	$childs = $cbvid->get_sub_categories(mysql_clean($_GET['cat']));
	$child_ids = array();
	if($childs)
		foreach($childs as $child)
		{
			$child_ids[] = $child['category_id'];
			$subchilds = $childs = $cbvid->get_sub_categories($child['category_id']);
			if($subchilds)
			foreach($subchilds as $subchild)
			{
				$child_ids[] = $subchild['category_id'];
			}
		}
	$child_ids[] = mysql_clean($_GET['cat']);
}
$vid_cond = array('category'=>$child_ids,'date_span'=>$_GET['time'],'sub_cats');

switch($sort)
{
	case "most_recent":
	default:
	{
		$vid_cond['order'] = " date_added DESC ";
	}
	break;
	case "most_viewed":
	{
		$vid_cond['order'] = " views DESC ";
	}
	break;
	case "most_viewed":
	{
		$vid_cond['order'] = " views DESC ";
	}
	break;
	case "featured":
	{
		$vid_cond['featured'] = "yes";
	}
	break;
	case "top_rated":
	{
		$vid_cond['order'] = " rating DESC, rated_by DESC";
	}
	break;
	case "most_commented":
	{
		$vid_cond['order'] = " comments_count DESC";
	}
	break;
}





//Getting Video List
$page = mysql_clean($_GET['page']);
$get_limit = create_query_limit($page,VLISTPP);
$vlist = $vid_cond;
$vlist['limit'] = $get_limit;
$videos = get_videos($vlist);
Assign('videos', $videos);	


//Collecting Data for Pagination
$vcount = $vid_cond;
$vcount['count_only'] = true;
$total_rows  = get_videos($vcount);
$total_pages = count_pages($total_rows,VLISTPP);
//Pagination
$pages->paginate($total_pages,$page);


subtitle(lang('videos'));
//Displaying The Template
template_files('videos.html');
display_it();





?>

Искам при проверка If гост - тази версия, else потребител - същата с допълнителния код за кеш

Код:
	$interval = 180 * 60;
	$filename = "/hdd2/data/cache/".basename( rtrim( $_SERVER["REQUEST_URI"], '/' ) ).".cache";

	// serve from the cache if less than 30 minutes have passed since the file was created
	if ( file_exists( $filename ) && (time() - $interval) < filemtime( $filename ) ) {
		readfile( $filename );
		exit(); // Terminate so we don't regenerate the page.
	}

	ob_start(); // This function saves all output to a buffer instead of outputting it directly.




PHP teksta idva tuk


	// More page generation code goes here

	$buff = ob_get_contents(); // Retrive the content from the buffer

	// Write the content of the buffer to the cache file
	$file = fopen( $filename, "w" );
	fwrite( $file, $buff );
	fclose( $file );

	ob_end_flush(); // Display the generated page.
 

Back
Горе