| Server IP : 104.21.80.248 / Your IP : 172.71.28.156 Web Server : Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30 System : Windows NT WIN-ECQAAA40806 6.2 build 9200 (Windows Server 2012 Standard Edition) i586 User : SYSTEM ( 0) PHP Version : 5.6.30 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /Inetpub/www/news/ |
Upload File : |
<?php
// แสดง error สำหรับ debug (ปิดได้เมื่อใช้งานจริง)
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
// อนุญาตให้แสดงใน iframe
header_remove('X-Frame-Options');
header("Content-Security-Policy: frame-ancestors 'self' *");
include("db.php");
if(!isset($_SESSION['username'])){
}else{
$username1 = $_SESSION['username'];
$user1 = $mysqli->query("SELECT * FROM users WHERE username='$username1' LIMIT 1");
if($user1) {
$userrow1 = mysqli_fetch_array($user1);
}
}
$sitesettings = $mysqli->query("SELECT * FROM settings WHERE id='1'");
if($sitesettings) {
$settingsrow = mysqli_fetch_array($sitesettings);
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><?php echo isset($settingsrow['site_name']) ? $settingsrow['site_name'] : 'News'; ?></title>
<meta name="description" content="<?php echo isset($settingsrow['meta_description']) ? $settingsrow['meta_description'] : ''; ?>" />
<meta name="keywords" content="<?php echo isset($settingsrow['meta_keywords']) ? $settingsrow['meta_keywords'] : ''; ?>" />
<script src="js/jquery.min.js"></script>
<script src="js/jquery.colorbox-min.js"></script>
<link href="css/style.css" rel="stylesheet" type="text/css">
<link href="css/colorbox.css" rel="stylesheet" type="text/css">
</head>
<body>
<div>
<!--title-->
<?php
// ตรวจสอบและกำหนดค่า default สำหรับพารามิเตอร์
$school = isset($_GET['school']) ? $mysqli->escape_string($_GET['school']) : '';
$limit = isset($_GET['limit']) ? intval($_GET['limit']) : 10;
// ตรวจสอบว่ามี school หรือไม่
if(empty($school)) {
echo "<div style='padding:20px; color:red; border:1px solid red; margin:10px;'>กรุณาระบุพารามิเตอร์ school<br>ตัวอย่าง: news.php?school=1&limit=10</div>";
exit;
}
// Query ข้อมูลจากตาราง sc_news
$story = $mysqli->query("SELECT * FROM sc_news WHERE cat_id='$school' ORDER BY id DESC LIMIT $limit");
// ตรวจสอบว่า query สำเร็จหรือไม่
if(!$story) {
echo "<div style='padding:20px; color:red; border:1px solid red; margin:10px;'>เกิดข้อผิดพลาดในการดึงข้อมูล: " . htmlspecialchars($mysqli->error) . "</div>";
exit;
}
// ตรวจสอบจำนวนข้อมูล
$rowCount = mysqli_num_rows($story);
if($rowCount == 0) {
echo "<div style='padding:20px; color:#666; border:1px solid #ccc; margin:10px;'>ไม่พบข้อมูลข่าวสาร</div>";
} else {
while($storyrow = mysqli_fetch_array($story)){
$description = stripslashes($storyrow['detail']);
$desc = strlen($description);
if ($desc > 140) {
$sdec = substr($description, 0, 500).'..';
} else {
$sdec = $description;
}
?>
<div class="story">
<h2><a href="view.php?id=<?php echo $storyrow['id'];?>" target="_blank"><?php echo htmlspecialchars(stripslashes($storyrow['title']));?></a></h2>
<p><a href="view.php?id=<?php echo $storyrow['id'];?>" target="_blank" style="text-decoration:none; color:inherit;"><?php echo strip_tags($sdec);?></a></p>
<?php
// ดึงข้อมูล user จาก uid
$userid = $storyrow['uid'];
$user = $mysqli->query("SELECT * FROM users WHERE id='$userid' LIMIT 1");
if($user && $userrow = mysqli_fetch_array($user)) {
$school_name = $userrow['school'];
} else {
$school_name = "";
}
?>
<div class="look-up-story">
<p>เปิดอ่าน : <?php echo $storyrow['views'];?> ครั้ง เขียนวันที่ : <?php echo $storyrow['date_news'];?><?php if(!empty($school_name)) { echo " | โรงเรียน: " . htmlspecialchars($school_name); } ?></p>
</div><!--look-up-->
</div><!--story-->
<?php
}
?>
<div align="right"><a href="category-<?php echo $school;?>-1.php" target="_blank">อ่านทั้งหมด</a></div>
<?php
}
?>
</div><!--news-box-->
</body>
</html>