Jump to content

[SOLVED] New to php


PeterRod

Recommended Posts

Hi,

I'm new to php. I have a shared resources website on GoDad running on a windows platform. All the webpages are .html. I successfully coded a php script for a contact form accessed via formAction. Now I want to try a simple todays date script from the .html page. It seems that the server/php is ignoring my embedded php script.

<?php

$time = time();

$tme = date("l jS F Y ", $time);

print "<p style ='position: absolute; top:6px; left:20px;font-size:14px;text-decoration:none; color:#c0c0c0'>$tme</p>";

?>

What should I do?

echo does not work also

I use notepad to edit and upload to the root directory as I do not have php/apache installed

 

 

Link to comment
Share on other sites

Did you say the code is in a file with a .html extension? By default the server will probably only parse PHP in files with the extension .php, So you could either change the extension, or if you don't wish to do this (as you don't want to mess up back links etc) you can (assuming you are able to add a .htaccess file) use a .htaccess file to tell Apache to parse php in .html files. I think it's something like...

 

AddType application/x-httpd-php .html

Link to comment
Share on other sites

Did you say the code is in a file with a .html extension? By default the server will probably only parse PHP in files with the extension .php, So you could either change the extension, or if you don't wish to do this (as you don't want to mess up back links etc) you can (assuming you are able to add a .htaccess file) use a .htaccess file to tell Apache to parse php in .html files. I think it's something like...

 

AddType application/x-httpd-php .html

 

Yes the php code is in a .html file. The website is on a windows platform so i believe there is no .htaccess file.  Where do I put your suggestion in the .html file? after <body> or where?

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

Did you say the code is in a file with a .html extension? By default the server will probably only parse PHP in files with the extension .php, So you could either change the extension, or if you don't wish to do this (as you don't want to mess up back links etc) you can (assuming you are able to add a .htaccess file) use a .htaccess file to tell Apache to parse php in .html files. I think it's something like...

 

AddType application/x-httpd-php .html

 

Yes the php code is in a .html file. The website is on a windows platform so i believe there is no .htaccess file.  Where do I put your suggestion in the .html file? after <body> or where?

 

So in this situation, your file should end with .php if you want to run php code inside it. Otherwise .html is not going to help.

Link to comment
Share on other sites

Yes the php code is in a .html file. The website is on a windows platform so i believe there is no .htaccess file.  Where do I put your suggestion in the .html file? after <body> or where?

 

No, the code provided was for a .htaccess file, if your running on a windows system you should still be able use .htaccess files so long as the site is being hosted with Apache.

Link to comment
Share on other sites

No, the code provided was for a .htaccess file, if your running on a windows system you should still be able use .htaccess files so long as the site is being hosted with Apache.

How do I do this? Yes my site is hosted with Apache I only have access to the root directory where I put my .html files. I can also get a listing of phpinfo but I cant find .htacess file to modify.

Link to comment
Share on other sites

No, the code provided was for a .htaccess file, if your running on a windows system you should still be able use .htaccess files so long as the site is being hosted with Apache.

If there is no access to the .htacess file then the first option is out.

 

2nd option  I put my php today code in a file Today.php how do I get the Today.php script to output text to the browser without using a form action=  . I believe there should be a way to get php scripts to run in a .html file without form action. I just dont know how.

Link to comment
Share on other sites

If you have no .htaccess file currently then you will need to create one. Just use whatever your favourite text editor is, type in just the line I placed in my previous post and save it as .htaccess. You should then place that in the root directory of your site. A couple of quick notes. Some applications won't allow you to save a file with the name .htaccess, so you may have to rename it afterwards. Second tip, alot of FTP applications ignore .htaccess as hidden files by default. For example in the latest FileZilla you have to select Server > Force showing hidden files, for the files to show.

 

There is no way (to my knowledge) to 'include' PHP code into a html file in the way you suggest (unless that html has functioning PHP code in it as PHP has an included facility).

Link to comment
Share on other sites

If you have no .htaccess file currently then you will need to create one.

I did as you suggested. I created ppl.htaccess with                        AddType application/x-httpd-php .html

as the only line.

Then I uploaded the ppl.htaccess file to the root directory of my site.

I placed this code at the end of my .html file but before </body>

<?php

$time = time();

$tme = date("l jS F Y ", $time);

print "<p  style ='font-size:20px;color:#f00'>$tme</p>";

?>

Note the color is red.

I get this output in the browser at the end of  my usual content

 

$tme

 

";?>

printed in black.

 

What am I doing wrong?

Seems as if the browser is still interpreting the php code as .html ???

Link to comment
Share on other sites

Your mistake is calling your file ppl.htaccess, a .htaccess file is called that because that is it's file name, it is not a file extention, that is the full filename, remove the ppl and try again.

Had to use the old MS-DOS REN command and I finally got the file named as  .htaccess

I get the same incorrect output as before. the site is

ppltt.com

and the php code is at the end of index.html. Maybe you can view the source and see if there is something wrong.

 

 

Thanks lots for your help

Maybe its because the site is on a Windows platform and not Linux

 

Link to comment
Share on other sites

I have not read the rest of the posts - sorry no time. If this has been discussed then sorry.

 

Rename the page index.php (instead of index.html)

 

Delete index.html from the server then go to www.ppltt.com

you probably should have read the rest of the posts...

 

Try contacting your host's support and see if you can access and edit the .htaccess file. Some hosts don't let you and if that is the case, you can try asking them to insert the line cags suggested also. if that doesn't work than I'm afraid you will have to make any page you hae PHP on a .php page

Link to comment
Share on other sites

Checked out your site, theres nothing wrong with the PHP structure at a glance so it's not that. It's still that your site isn't parsing the PHP. Can I just confirm the .htaccess file is in the same directory as the index.html. It being hosted on windows shouldn't really matter, I use .htaccess files on my localhost, which is running on Windows XP. It's possible your host doesn't allow .htaccess files, they can be disabled in the configuration.

 

Btw, I use Notepadd++ to work with .htaccess files (and many other files), it allows you to save directly as .htaccess and it's free.

 

I have not read the rest of the posts - sorry no time. If this has been discussed then sorry.

 

Rename the page index.php (instead of index.html)

 

Delete index.html from the server then go to www.ppltt.com

 

That would obviously work, but any links to http://www.ppltt.com/index.html would no longer work. Since it is the root index file it could be worse as most links probably point to just the domain, but still you could potential lose links. Obviously you could always use .htaccess files to redirect index.html to index.php.... oh wait, we might as well just get php working in html if we can get .htaccess working, lol :)

Link to comment
Share on other sites

It's possible your host doesn't allow .htaccess files, they can be disabled in the configuration.

Rename the page index.php (instead of index.html)

Delete index.html from the server then go to www.ppltt.com

OK its clear now GoDad does not allow .htaccess files.

So I simply rename any files with php scripts as .php and ensure that backlinks are consistent with changes. That seems easy enough.

 

Thanks for the help. I'll consider this solved.

Peter

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.