PDA

View Full Version : .htaccess file



Mana
05-14-2008, 06:00 AM
Alright...I want to force a XML file into reading as PHP.

This is the XML file:


<?php

define('NAGARATUBE_GETVIDEO_URL', 'x/get_video.flv');

require_once 'YouTube.class.php';

session_name('nagaratube');
session_start();

$type = (isset($_SESSION['type']) and is_numeric($_SESSION['type']))? (int) $_SESSION['type']: 0;
$query = (isset($_SESSION['query']) and !empty($_SESSION['query']))? $_SESSION['query']: '';
$category = (isset($_SESSION['category']) and is_numeric($_SESSION['category']))? (int) $_SESSION['category']: 0;
$sort = (isset($_SESSION['sort']) and !empty($_SESSION['sort']))? $_SESSION['sort']: '';

if (empty($query)) {
$params = array(
'method' => 'youtube.videos.list_popular',
'time_range' => 'day'
);
$popular = YouTube::requestApi($params);
$params = array(
'method' => 'youtube.videos.list_featured'
);
$featured = YouTube::requestApi($params);
$result = array_merge($popular, $featured);
} else {
switch ($type) {
case 1:
$params = array(
'method' => 'youtube.users.list_favorite_videos',
'user' => $query
);
break;
case 2:
$params = array(
'method' => 'youtube.videos.list_by_playlist',
'id' => $query,
'page' => 1,
'per_page' => 100
);
break;
default:
if ($category > 0) {
$params = array(
'method' => 'youtube.videos.list_by_category_and_tag',
'category_id' => $category,
'tag' => $query,
'page' => 1,
'per_page' => 100
);
} else {
$params = array(
'method' => 'youtube.videos.list_by_tag',
'tag' => $query,
'page' => 1,
'per_page' => 100
);
}
}
$result = YouTube::requestApi($params);
}
if (!empty($sort) and isset($result[0][$sort])) {
sortMultiArray($result, $sort);
} else {
shuffle($result);
}

header('Content-Type:application/xml;charset=UTF-8');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
echo "<playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">\n";
echo "\t<trackList>\n";
foreach ($result as $value) {
echo "\t\t<track>\n";
echo "\t\t\t<title>".htmlspecialchars($value['title'])."</title>\n";
echo "\t\t\t<creator>".htmlspecialchars($value['author'])."</creator>\n";
echo "\t\t\t<location>".NAGARATUBE_GETVIDEO_URL."?v=$value[id]</location>\n";
echo "\t\t\t<meta rel=\"type\">flv</meta>\n";
echo "\t\t\t<image>$value[thumbnail_url]</image>\n";
echo "\t\t\t<info>$value[url]</info>\n";
echo "\t\t</track>\n";
}
echo "\t</trackList>\n";
echo '</playlist>';

function sortMultiArray(&$array, $sortby)
{
$keys = array();
foreach ($array as $key => $value) {
$keys[$key] = $value[$sortby];
}
array_multisort($keys, SORT_NUMERIC, SORT_DESC, $array);
}

?>



And this is my .htaccess file (on the same folder as the XML file):



<Files ~ "^.*\.(inc|class)\.php$">
order deny,allow
deny from all
</Files>
Add AddType application/x-httpd-php .xml
Add AddType application/x-httpd-php .flv
AddType application/x-httpd-php .xml
AddType application/x-httpd-php .flv
<Files ~ "^(playlist.xml|get_video.flv)$">
ForceType application/x-httpd-php
</Files>
<Files ~ "^(playlist\.xml|get_video\.flv)$">
ForceType application/x-httpd-php
</Files>

php_flag magic_quotes_gpc off
php_flag session.auto_start off


But when I tried to view the XML file online, it shows me a blank page. I viewed the source and I got:

<!-- SHTML Wrapper - 500 Server Error -->
What did I do wrong?

linFox
05-14-2008, 08:12 PM
From your .htaccess, remove the two Add Addtype ... lines, the second <Files> block and the php_flags (you'll have to set those in php.ini).
That should fix the Server Errors coming from .htaccess, at least.

sjlplat
05-15-2008, 08:11 AM
You can achieve this by using AddHandler instead of AddType.