So I've created a php webpage with a head section that links to some bootstrap css files and my custom css file. This webpage also has a foot division that links to the necessary jQuery and bootstrap JavaScript files. That's all fine and dandy: I know it works because when I launch this .php in firefox, I can see that Bootstrap has taken control and stylized the text. The problem occurs when I try to break this webpage up into components...
I've created a separate head.html and foot.html which include the same content as before they were broken up, and on the .php page I use the following include statements:
<?php include '../components/head.html'; ?>
<?php include '../components/foot.html'; ?>
Now when I launch the php from my browser, the links clearly haven't worked because the text is not styled. Upon choosing to "view source" of the .php, I see that it has not included the markup from head.html or foot.html, and instead I still see the literal <?php include '';> statements. What have I done wrong? I know the relative filepaths are correct, so perhaps it has something to do with the fact I'm trying to launch the php page locally? Perhaps the components should be .php instead of .html? I really don't know.
Additional info: Win7, tried using notepad++ because Dreamweaver keeps giving me FTP errors every time I ask to "preview in browser"
First you should have a webserver installed along with PHP. You may use xampp or wampp. If you simply open a php file in your browser then it will not execute the PHP statements instead will display the code as it is.
Except for not having a web server along with PHP installed in your system you have done nothing wrong as I see.
The head.html and foot.html can be html files and not .php files that would not be an issue till the file containing the include statment is .php file.
Related
I need to include some php code on my contact form page so I tried changing the file extension from .html to .php and either my css page no longer connects or the html isn't even displaying properly. When open in a web browser only the lines of code (of the new php doc) as typed appear. Before changing the extension everything is styled and layed-out correctly, only changing the extension completely breaks it. Why is this? and how do I fix it?
Create a new php file and copy the content from that page to the new file and see if it works
fix: I had a firewall blocking my localhost server when I tried opening the website folder. I just needed to whitelist the port. Thanks for the suggestions !
I am experimenting with using AWS. To be specific, I am following the tutorial at this link:
https://aws.amazon.com/getting-started/hands-on/build-web-app-s3-lambda-api-gateway-dynamodb/module-three/?e=gs2020&p=build-a-web-app-two
I have tried to add empty PHP tags to the start of the file and renamed the file to index.php instead of the index.HTML of the tutorial. I did a full sequence of refreshing the web app resources and deploying the app on the Amplify console. It did not work. I tried only using the HTML code on index.php and it still did not work. I put back the PHP code, added an echo statement echo "<h1>PHP Code Ran</h1>"; but renamed the file to index.html and it did render. Granted, there was an error in the text output. It also wrote the ending semi-colon and ending quotation, but it worked.
Is there any way for me to use a file named index.php as the home page of a web app using AWS amplify?
A PHP file isn't just an HTML file with a different name: you need to have a server somewhere that's running PHP which will look at the PHP code and run it.
If you're just uploading files to S3, that's not going to happen, the file is just going to be sent straight to the browser, regardless of what you call it and what you put in it.
Putting <?php echo "<h1>PHP Code Ran</h1>"; ?> into a file "worked" only in the sense that when you opened the page in the browser, you saw your browser's best attempt to interpret that as HTML. If you go to "View Source", you'll see that the file is exactly what you uploaded to S3, no PHP has run at all.
If you want to write a PHP application, you need to understand how to run PHP - most likely on an EC2 server, but it could also be in a Fargate container, or something even fancier like bref which lets you run PHP in a Lambda function.
I am having issues while running the live preview of some php files on LOCALHOST. Like I am working on Wordpress theme and while I am able to set the correct base URL and open the file on the browser through index.php, but I am not able to edit and view the other php files.
For example, I have to open index.php which is in http://localhost/test but suppose I want to edit the header.php file. I click on the header.php file and it opens a new page in Browser with URL, http://localhost/test/header.php, which returns a 404 error through wordpress(OOPS PAGE NOT FOUND!)
I have very little work with index.php and mostly with header, footer, functions and everything else. Although this isn't really a big issue, I can go with the traditional way but I really wanted to utilize this Brackets Feature. Hope there's something to get past this :)
This is not an issue this will never open in browser like single file, if you want to check this then header.php and footer.php files are also included into the index.php , you will check from that no need to run them to browser.
I have made a custom theme with wordpress locally with wamp.I use notepad++ for writing my code.Some days before when I wanted to load my page from notepad I had to go to run->launch in Firefox and had no problem showing the page where in the address bar the URL was:localhost/wordpress.
Now when I try to load my php files from notepad (run ->launch in Firefox) it shows a corrupt html page not all of it ,with some rules of php and without CSS and no images.In the address bar when running my project from notepad the URL is file:///C:/wamp/www/wordpress/wp-content/themes/revenant/page-about-us.php which is incorect ofcourse.Also it does not understand the php code.For example the title for about us page is
<?php echo get_the_title('about-us'); ?>
But when I write manually in the address bar the URL of my project like localhost/wordpress everythng shows as they shown before with no problem.I have not changed any settings in notepad.Why this problem came up with no reason?Why it doesnot load php and css? Thank you!
Notepad++ doesn't know that you have a webserver running or what the document root is, so it cannot take you to the file's URL. When it opens the file in the browser, it is loading the file directly off the hard drive (hence the file://). It is not being served by the webserver that knows how to parse PHP, it is being read directly by the browser, which does not.
I want to use some php to make simple header/footer files for my webpages. I'm just getting started in web design and I am using Coffee Cup HTML Editor.
Problem is I have this line in my index.php file:
?php include(“includes/header.html”);?>
and nothing shows up even though my header.html file has a menu in it.
Do I need to install something on my machine before PHP code will show anything?
Syntax errors
Firstly, your code snippet contains a syntax error. The opening PHP tag should be <?php and not ?php. So your code should look like this:
<?php include('includes/header.html');?>
Install PHP
Secondly, you need to run PHP scripts on a PHP server like XAMPP for the code to actually be executed.
This assumes header.html either contains text or if it is PHP it echo()s its output.