PDA

View Full Version : ثبت کوکی در مرورگر



morteza5691
پنج شنبه 20 فروردین 1394, 19:02 عصر
سلام خدمت اساتید محترم

من برای ارسال فایل از سرور به کاربر (دانلود) از تابع readfile استفاده کردم. ولی متاسفانه باعث شده تابع setcookie عمل نکنه!!!!:اشتباه:
وقتی readfile رو برمیدارم کوکی ثبت میشه.

به نظر شما باید چیکار کنم؟؟ :متفکر:

نمونه کد :


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Read File</title>
</head>

<body>
<?php
$filename = "123.mp4";
$filesize = filesize($filename);

if($_POST['download'] == true) {
if(setcookie("morteza", "ReadFile", time()+86400,"/")) {
header('Content-Description: File Transfer');
header('Content-Type: video/mp4');
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: '.$filesize);
ob_clean();
flush();
readfile($filename);
}
else {
echo "False";
}
}

echo $_COOKIE["morteza"];
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="download" value="true" />
<input type="submit" name="submit" value="Download!" />
</form>
</body>
</html>

morteza5691
جمعه 21 فروردین 1394, 20:28 عصر
up :متفکر:

morteza5691
شنبه 22 فروردین 1394, 16:45 عصر
UUUUUPPPP :ناراحت:

j_naroogha@yahoo.com
یک شنبه 23 فروردین 1394, 14:03 عصر
کد تون خطا داره .چون چک نکرده بودین آیا پست شده یا نه؟ الان ببینین درست نشد؟


<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Read File</title>
</head>

<body>
<?php
$filename = "123.mp4";
$filesize = filesize($filename);
if(isset($_POST))
{
if($_POST['download'] == true) {
if(setcookie("morteza", "ReadFile", time()+86400,"/")) {
header('Content-Description: File Transfer');
header('Content-Type: video/mp4');
header('Content-Disposition: attachment; filename='.$filename);
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: '.$filesize);
ob_clean();
flush();
readfile($filename);
}
else {
echo "False";
}
}

echo $_COOKIE["morteza"];
}
else {


?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="download" value="true" />
<input type="submit" name="submit" value="Download!" />
</form>
</body>
</html>
<?php }
?>

morteza5691
دوشنبه 24 فروردین 1394, 18:14 عصر
ممنون داداش . . . ولی چیزی که شما نوشتین اصلا درست نیست.

ربطی نداره :خجالت: کلا وقتی readfile() داریم تو صفحه ، کوکی ثبت نمیشه . . . اگه readfile() رو پاک کنید ثبت میشه.

اینو دیگه بیخیال . . . با روش های دیگه ای این مشکلمو حل کردم. بازم ممنون