Hello!!
For a client, I designed a feature which allows a panel user to download a csv file (list of emails) filed from a form in the home page.
Public users fill the form and a structure field is updated, in a specific page.
I want to restrict the possibility to download the file, only for registered panel users.
It works on locahost environnement, on my compnay’s server but not in my client server (of course…).
I did:
-
Blueprint of addemails.yaml : the structure field and an info section “To download, click here” (link to the current page which suppose to be available for registered user only)
-
Template addemails.php, the page which create the csv file, with only:
<!DOCTYPE html>
<html lang="fr">
</html>
- Controllers to check registered users and create the file
<?php
return function ($kirby, $page) {
// Create file for registered users only
if ($kirby->user()) {
header("Content-type: text/csv");
header("Content-disposition: attachment; filename=liste-emails.csv");
$listemails = $page->listeEmail()->toStructure();
$emails = [];
foreach($listemails as $item) {
$emails[] = $item->email();
}
$fp = fopen('php://output', 'wb');
foreach ( $emails as $line[0]) {
fputcsv($fp, $line, ',');
}
fclose($fp);
exit();
}
else {
go('/');
};
}
?>
Any idea why this works depending on the environnement?
I checked different conf:
- Same browser (Brave) but different identity : download without authenitification
- Trying with Edge : Can’t download but once I’ve logged in and out, I can download without authenitification
Thanks for you help!