Skip to main content

why does my .PHP produced .html work only after being pasted into another .html file? [closed]


Summary: https://www.lootjeapp.nl/Lootje/producedAndSavedByPHPAndSomethingWrong.html is what my .php file created, and it is not displayed right.

However, when I copy it's source code and put it into a new .html file, it works like a charm: https://www.Lootjeapp.nl/Lootje/sourceOfErroredPage.html

Everything looks fine, and apparently it's source code is fine so Why won't the original work?


I created a .php page that can take a $POST request and then creates a brand new .html page according to the variables received.

<?php


$onderwerp = $_POST['onderwerp'];
$Speler1 = $_POST['Speler1'];
$Speler2 = $_POST['Speler2'];
$string1 = "  background-image: url('https://www.lootjeapp.nl/forestbridge.jpg');";


//We use the input to create a new page 
    
$newPage="../../Lootje/$onderwerp$Speler1$Speler2.html";

//Maybe naming the page this way creates a problem for browsers to fully recognise it as html

$fh = fopen($newPage, 'w'); 


//below writes the html code for the new page 
fwrite($fh,"<!DOCTYPE html>\n");
fwrite($fh,"<html>\n");
fwrite($fh,"<title>W3.CSS Template</title>\n");
fwrite($fh,'<meta charset="UTF-8">');
fwrite($fh,'<meta name="viewport" content="width=device-width, initial-scale=1">');
fwrite($fh,'<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">');
fwrite($fh,'<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">');
fwrite($fh,'<style>');
fwrite($fh,'body,h1 {font-family: "Raleway", sans-serif}');
fwrite($fh,'body, html {height: 100%}');
fwrite($fh,'.bgimg {');



//the fwrite syntax had a problem because the syntax for the background image file was seen as closing the argument, hence the $string1 introduction
fwrite($fh,$string1);
fwrite("\n");


fwrite($fh,'  min-height: 100%;');
fwrite($fh,'  background-position: center;');
fwrite($fh,'  background-size: cover;');


fwrite($fh,"\n}");

fwrite($fh,'</style>');
fwrite($fh,'<body>');
fwrite($fh,"\n");

fwrite($fh,'<div class="bgimg w3-display-container w3-animate-opacity w3-text-white">');
fwrite($fh,'  <div class="w3-display-topleft w3-padding-large w3-xlarge">');
fwrite($fh,"\n    Logo");
fwrite($fh,"\n </div>\n");

fwrite($fh,'  <div class="w3-display-middle">');
fwrite($fh,'    <h1 class="w3-jumbo w3-animate-top">LOOTJE</h1>');
fwrite($fh,'    <hr class="w3-border-grey" style="margin:auto;width:40%">');
fwrite($fh,'    <p class="w3-large w3-center">35 days left</p>');

fwrite($fh,'  </div>');
fwrite($fh,'  <div class="w3-display-bottomleft w3-padding-large">');
fwrite($fh,'    Powered by <a href="https://www.w3schools.com/w3css/default.asp" target="_blank">w3.css</a>');

fwrite($fh,'  </div>');
fwrite($fh,'</div>');
fwrite($fh,'</body>');
fwrite($fh,'</html>');


fclose($fh);
?>

The good news is that the new .html file does get created and the syntax is exactly what it should be. (although it looks ugly)

<!DOCTYPE html>
<html>
<title>W3.CSS Template</title>
<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"><link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway"><style>body,h1 {font-family: "Raleway", sans-serif}body, html {height: 100%}.bgimg {  background-image: url('https://www.lootjeapp.nl/forestbridge.jpg');  min-height: 100%;  background-position: center;  background-size: cover;
}</style><body>
<div class="bgimg w3-display-container w3-animate-opacity w3-text-white">  <div class="w3-display-topleft w3-padding-large w3-xlarge">
    Logo
 </div>
  <div class="w3-display-middle">    <h1 class="w3-jumbo w3-animate-top">LOOTJE</h1>    <hr class="w3-border-grey" style="margin:auto;width:40%">    <p class="w3-large w3-center">35 days left</p>  </div>  <div class="w3-display-bottomleft w3-padding-large">    Powered by <a href="https://www.w3schools.com/w3css/default.asp" target="_blank">w3.css</a>  </div></div></body></html>

new file after POST requestugly but the correct html It shows up in the right folder and the code is fine.

HOWEVER when opening this new .html file in a browser the page is not loaded correctly. Obviously, some style element is mixed up. check it here https://www.lootjeapp.nl/Lootje/producedAndSavedByPHPAndSomethingWrong.html some style element seems wrong

To check its .html, I displayed the Source Code from the browser and copied it to clipboard copy the html Then I created a new empty file and pasted the code therenew file in same directory enter image description here. Opening that .html file in a browser displays the website without any problems (10)that same html is working fine here

So .PHP seems to generate very capable HTML code but there is something keeping it from working via the file that was created by fopen(). It is only after copying the source code to a new .html that it works flawlessly.

Is there anyone who can think of a reason why the originally .html created would not work?

(It concerns this site: https://www.lootjeapp.nl/Lootje/producedAndSavedByPHPAndSomethingWrong.html)



source https://stackoverflow.com/questions/68971898/why-does-my-php-produced-html-work-only-after-being-pasted-into-another-html

Comments

Popular posts from this blog

How to show number of registered users in Laravel based on usertype?

i'm trying to display data from the database in the admin dashboard i used this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count(); echo $users; ?> and i have successfully get the correct data from the database but what if i want to display a specific data for example in this user table there is "usertype" that specify if the user is normal user or admin i want to user the same code above but to display a specific usertype i tried this: <?php use Illuminate\Support\Facades\DB; $users = DB::table('users')->count()->WHERE usertype =admin; echo $users; ?> but it didn't work, what am i doing wrong? source https://stackoverflow.com/questions/68199726/how-to-show-number-of-registered-users-in-laravel-based-on-usertype

Why is my reports service not connecting?

I am trying to pull some data from a Postgres database using Node.js and node-postures but I can't figure out why my service isn't connecting. my routes/index.js file: const express = require('express'); const router = express.Router(); const ordersCountController = require('../controllers/ordersCountController'); const ordersController = require('../controllers/ordersController'); const weeklyReportsController = require('../controllers/weeklyReportsController'); router.get('/orders_count', ordersCountController); router.get('/orders', ordersController); router.get('/weekly_reports', weeklyReportsController); module.exports = router; My controllers/weeklyReportsController.js file: const weeklyReportsService = require('../services/weeklyReportsService'); const weeklyReportsController = async (req, res) => { try { const data = await weeklyReportsService; res.json({data}) console...

How to split a rinex file if I need 24 hours data

Trying to divide rinex file using the command gfzrnx but getting this error. While doing that getting this error msg 'gfzrnx' is not recognized as an internal or external command Trying to split rinex file using the command gfzrnx. also install'gfzrnx'. my doubt is I need to run this program in 'gfzrnx' or in 'cmdprompt'. I am expecting a rinex file with 24 hrs or 1 day data.I Have 48 hrs data in RINEX format. Please help me to solve this issue. source https://stackoverflow.com/questions/75385367/how-to-split-a-rinex-file-if-i-need-24-hours-data