Link to home
Start Free TrialLog in
Avatar of intercodes
intercodes

asked on

php in html

i have a quote php script that generates random quotes (the file is quote.php) . I want the quote to be in my main page(index.htm) ..that is i want to display the quote.php( which contains a single radomly generated code) in my home page in a corner.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Zyloch
Zyloch
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of joeposter649
joeposter649

you could also use javascript for this..

Firstly - Strongly advise against an IFrame.

If anything use Zylochs comment.
Much better.
Seems like the perfect place to use an iframe to me if they want to keep index.htm.
An iframe would work in the situation, but if you have a quote.php page, I'm assuming you have PHP on your server so...
The problem is, how can he include the quote on the page with an iframe...
the iframe will take up a block of room - there is no need at al.

if the server can compile PHP for the quotes.php file - the BEST possible solution would be to make the index file a PHP file.
Avatar of intercodes

ASKER

So changing my index.htm to index.php doesnt affect my present contents in index.htm. i mean it is witten in HTMl and contains lot's of stuff..those stuff wud be intact if i change my index to php extension?
It shouldn't.  
http://www.w3schools.com/php/php_syntax.asp

But your site will be affected if you have links in your site to index.htm or if a user has bookmarked it.
Intercodes:

No the .php will only mean that the PHP compiler will run through the page.

It ignored everything that isn't included inside the <?PHP ?> tags.
So anything else is just sent to the browser like normal.

So if you just have this in your page:

<?php include("quote.php"); ?> -or-
<?php include_once("quote.php"); ?> - that will stop any problems if yuo have any sort of recurring page load etc...
Not really too applicable here...

What JOEPOSTER said is true.



----------------

BUT

You can fix that simply by, creating a file called: .htaccess
inside the .htaccess file have this code:

ReWriteEngine On
ReWriteRule ^index.html$ index.php


That will allow you to run the PHP with the HTML file...
To Sum It All up...



1] RENAME THE FILE TO, index.php
2] INSERT THIS CODE TO INCLUDE THE QUOTES: <?php include("quote.php"); ?>
3] CREATE FILE CALLED: .htaccess - INSIDE THE MAIN FOLDER OF THE WEBSITE
4] ADD THIS CODE TO THE .htaccess FILE:
          ReWriteEngine On
          ReWriteRule ^index.html$ index.php
5] UPLOAD AND ITS ALL DONE!

You can navigate to: www.yoursite.com/index.html
and the server will simply load the index.php file!!
But to the user, it will appear to just be the HTML file :)
easy done...
No need to change links anywhere.
To make sure other sites can still go to index.html, you can use mod_rewrite like neester said (which would only work on Apache servers), or you can set your server to accept .html files as PHP in your httpd.conf file (if Apache).
um.  you might want to check if you have a .htaccess file already, and edit that one.
True PJargon,
You woudlnt want to overwrite any current htaccess directives