To avoid hacking I created an admin page in ad-min.php.inc where you can login.
When I try to access ad-min.php.inc all my php script is commented:
<?php
echo "Hello";
?>
Ends up in the broswer blank with:
<!--<?php
echo "Hello";
?>-->
How could I fix this? On my local computer everything work (on a Mac) but when I set it up in the server it doesn't work. Thank you, sorry for bad explanation.
I think the problem you are running into is that your page doesn't have a *.php extension, meaning the server doesn't know how to interpret it, or that it is a PHP script.
Three ways to fix this:
Setup a mime-type in your .htaccess file to have .inc files interpreted as PHP:
AddHandler application/x-httpd-php .inc
Otherwise you can include the file in another file with a *.php extension:
<?php include('ad-min.php.inc'); ?>
Or simply rename the file to be ad-min.php
Best of luck!
Related
I am trying to wrap my head around php and html, and wanted to ask some help with what I guess are basics.
I am aware that you can run a php script on a single line in a .html page with tags. The problem comes when I have a longer script on multiple lines (It generates a table) that I run from localhost:
<?php
$rows = 10; // define number of rows
$cols = 10;// define number of columns
echo "<table border='1'>";
for($tr=1;$tr<=$rows;$tr++){
echo "<tr>";
for($td=1;$td<=$cols;$td++){
echo "<td>Fill</td>";
}
echo "</tr>";
}
echo "</table>";
?>
The above will come out as plain text after first ">" sign, so I guess for some reason the page reads it as I close the php snippet and executes rest as plain HTML (I run the file through apache). I am aware that you can rename the file to .php instead, and get whole thing working, but I want to understand know how PHP behave on HTML pages.
So I have two questions:
1) Is it possible to make the .html read the above code snippet without breaking it apart? I've tried htmlspecialchars, didn't help.
2) Is it possible to have the above snippet as a separate .php file, that I call from .html page like I can call a javascript function? I've tried <?php include 'field.php';?> which didn't work. I've looked into .htaccess, but it seems that's a solution for live versions, which didn't work for me.
Thank you!
The above will come out as plain text after first ">" sign,
PHP is not being processed. Probably because you're using the .html extension. Use .php.
.html will only work if you specifically tell Apache to treat .html as a PHP file.
It looks like you actually aren't evaluating the PHP at all. I suggest you view source, and then you'll see that the browser is actually trying to render all of this as a tag in the document:
<?php
$rows = 10; // define number of rows
$cols = 10;// define number of columns
echo "<table border='1'>
While it isn't impossible to have files with the extension .html render PHP (or Perl, or Python, or what have you), it is uncommon for a server to have that set up by default. I suggest changing the file's extension to .php. If your server is set up to process PHP at all, that will cause it to properly evaluate the script.
You need to set Apache to read HTML files as PHP. Find your php.conf, its usually is the etc directory like : /etc/apache/mods-enabled/php.conf
Add the following to the file:
<FilesMatch ".+\.html$">
SetHandler application/x-httpd-php
</FilesMatch>
And then restart the apache service:
service apache restart
The modules on your server might have different names, too. Apache may be apache or apache2 and your PHP may have the version after the name like php5. This should be reflected in both the directory in which your PHP conf file is located and the service that you restart.
Once your conf file is updated, Apache will treat all html files as PHP and you should be able to put as much PHP code as you want throughout the file. Note: The PHP parser will only work if you use <?php to open (or <? open if short tags are enabled) and ?> to close your PHP bits.
I am trying to run PHP in HTML page.
I saved this file in WAMP as a .html
<html>
<body>
<?php echo "My first PHP script!";?>
</body>
</html>
But when I open it with the browser and I do inspect element the result is this:
<html>
<head></head>
<body>
<!--?php
echo "My first PHP script!";
?-->
</body>
</html>
If Apache is not running .html pages as php scripts then running a .html page won't run as .php
Solution: Rename your filename from something.html to something.php
or alternatively something.phtml although this is uncommon
You can also save the page as .phtml. This format is possible of displaying .php & .html.
Take a look here for more information: What is phtml, and when should I use a .phtml extension rather than .php?
You should save it as .php instead of .html
You need to put it into a .php file, the webserver (if not configured so) won't interpret .html files as PHP.
Like others said, by changing file extension from .html to .php would work. However, if you don't want to do that, you may want to check this out. It allows you to execute php file without change file extension.
I'm trying to migrate a Webshop to a new Webserver. It is working perfectly fine on the old Webserver, however, when I try to login at the Webshop (index.html) it returns to the homepage, not logged in as the Session Variable is empty.
Then I noticed, when I opened another Site called request.php) the Session Variable was set and I was logged in.
So I tried several things, I renamed the index.html to index.php and the session was there.
My question is now: Can I get the Session in .html files, too (as on the previous Webserver) or do I have to rename all my .html files?
Note: The index.html file contains php code as well and is parsed as php, just the session variable is empty.
Thanks in advance for every answer!
if you are using a Apache Server, try add this to the config file.
AddType application/x-httpd-php .html
You need to set a handler in your web server to treat html files as php files.
The files need to be renamed to have a .php extension on them, even if they include html.
Simply include your php code before the html starts, like so:
<?php
//code goes here
?>
<html>
<body>
//etc...
This way, you can load up your session variable and any other PHP variables you need, then they'll be accessible in the html as well.
If you have several pages that will need the same thing (session variable), you could put the session code into a php file, something like 'session.php'.
Then, at the top of every page you're converting from html to php, put this code at the top:
<?php
require_once("session.php");
?>
Now all of your pages will have access to the same information, and it helps to cut down on the code too.
AddType application/x-httpd-php .html
In your .htaccess file will do the job, still I believe it's rather unsafe to do it :)
I am new to PHP. I am developing php under Redhat.
The index.html is like this:
<?php
$myvar="AAAA";
echo $myvar;
?>
But nothing is output in the browser.
Any help?
Rename the file to index.php and it should work.
If that fixes it the problem was that the webserver (presumably Apache) knows that .php files should be rendered with PHP but it correctly ignores .html files.
From what i see, the file is interpreted as HTML and not PHP. If you see the source of the page, you will see your PHP code.
Try renaming the file to index.php and if your server is set up properly, it should interpret the PHP code.
Change the file extension from .html to .php and your code will work fine.
I have a website made and i have saved the file as .html, I now want to add a .php file. Is this possible as i have tried so hard to do this. Id appreciate any help given :)
You can do several things.
Rename your .html files to .php.
Tell your web server to pass .html files to the PHP interpreter. In Apache you'd do this by putting AddType application/x-httpd-php .html .htm in your .htaccess file or your Apache configuration.
If you have installed PHP, you can rename your file to *.php and insert PHP codes!
You want to put PHP code inside a .html file? You'd have to configure the webserver to treat the .html file as a PHP script. Technically, there's no such thing as a PHP script. There's only files which have at least one <?php ?> code block within them. As such, ANY file can contain PHP code. The problem is getting that file into the PHP environment.
Unless your webserver is told to hand the .html file over to the PHP interpreter, you cannot execute the PHP code contained within it - the raw code will get sent out as part of the html page.
Just rename your .html file to .php, if your webhost supports it.
If you run your own server you can even configure PHP to also run .html files, but it's not recommended because of the performance penalty on all html files.
Yes, you can include php file into html file. i m sure that this link will help you.
http://php.about.com/od/advancedphp/p/html_php.htm