Reply
PHP code within HTML document
Old 04-09-2008, 10:55 PM PHP code within HTML document
Robert_R's Avatar
Skilled Talker

Posts: 88
Location: New Jersey
Trades: 0
I'm trying to put a countdown script on my page(s). It will just show up on every page. It's not triggered by clicking on a link.

Currently I have the entire PHP code inside of my HTML document.

How can I, I guess "call" would be the proper terminology, have that PHP execute from outside of my HTML.

In other words so my PHP code, besides the one line I suppose, is not in my HTML document?

Thanks!
Robert_R is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 04-09-2008, 11:01 PM Re: PHP code within HTML document
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,577
Name: Keith Marshall
Location: West Hartford, CT
Trades: 0
You can include external scripts by using include() in PHP. You can include anything really, but if its another php page, it will also parse during the execution.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is online now
Reply With Quote
View Public Profile
 
Old 04-10-2008, 08:39 AM Re: PHP code within HTML document
Robert_R's Avatar
Skilled Talker

Posts: 88
Location: New Jersey
Trades: 0
I am a novice with PHP. Would you be as so kind as to give me an example and/or point me to a link?

Thank you.
Robert_R is offline
Reply With Quote
View Public Profile
 
Old 04-10-2008, 09:23 AM Re: PHP code within HTML document
rogem002's Avatar
Super Spam Talker

Latest Blog Post:
Making Zebra Stripes with CSS3
Posts: 834
Name: Mike
Location: United Kingdom
Trades: 0
PHP Code:
<?php
include("file_link");
?>
file_link should be something like /home/username/public_html/includes/filename.inc.php it's relative to your server not externall (like not yousite.com/includes/filename.inc.php).
__________________
PHP Code:
Add_Talkupation('rogem002'); // Because sharing is awesome! 
Fix 90% of your problems | Full On Design

Last edited by rogem002; 04-10-2008 at 09:26 AM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 04-10-2008, 01:20 PM Re: PHP code within HTML document
lizciz's Avatar
Ultra Talker

Posts: 430
Name: Mattias Nordahl
Location: Sweden
Trades: 0
You can read about the include() function on php.net
http://se2.php.net/manual/en/function.include.php

You can also use include_once(), require() or require_once() which pretty much does the same thing (of course there are differenses). They are also available on php.net
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 04-10-2008, 06:50 PM Re: PHP code within HTML document
Gilligan's Avatar
Dead Like Me

Posts: 1,632
Name: Stefan
Location: London, UK
Trades: 0
I would use include() in this case, but there are many other ways. Such as having a config.php and echoing the countdown on every page.

Eg:

config.php

PHP Code:
<?php 

$countdown 
'code for countdown here'

?>
any other page.

PHP Code:
<?php 

echo $countdown 

?>
__________________
DoThatDesign.com - Professional Website Design - FREE Quotes!
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 04-10-2008, 07:02 PM Re: PHP code within HTML document
whym's Avatar
Defies a Status

Posts: 3,429
Trades: 0
Quote:
Originally Posted by rogem002 View Post
PHP Code:
<?php
include("file_link");
?>
file_link should be something like /home/username/public_html/includes/filename.inc.php it's relative to your server not externall (like not yousite.com/includes/filename.inc.php).
That's slightly misleading - you don't need to enter the /home/username/public_html stuff every time. Let's say I have a website called mywebsite.com and a file in public_html called hello.php. (accessible to the world by typing mywebsite.com/hello.php).

Well to include that file in another file called test.php which is also in the public_html directory, I would type:

PHP Code:
<?php include('hello.php');?>
If the hello.php was in a folder beneath public_html, I would type the folder such as:

PHP Code:
<?php include('somefolder/anotherfolder/hello.php');?>
What I'm basically saying is that you don't need to type in the /home/username/public_html stuff in every time usually - it will work fine without it.

Dan
__________________
Whym Web Design
whym is offline
Reply With Quote
View Public Profile Visit whym's homepage!
 
Old 04-10-2008, 07:48 PM Re: PHP code within HTML document
Gilligan's Avatar
Dead Like Me

Posts: 1,632
Name: Stefan
Location: London, UK
Trades: 0
I use it, but mainly because I'm calling the page from inside 4 folders.

its better than doing ../../../../db.php

Easier editing, better knowing of where the files are. Just my opinion though.
__________________
DoThatDesign.com - Professional Website Design - FREE Quotes!
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 04-11-2008, 03:00 AM Re: PHP code within HTML document
melanko's Avatar
Average Talker

Posts: 15
Trades: 0
I would agree with everyone else, use the include() function.

I've wondered though, what's the reason to use .inc.php rather than just .php for file names.
melanko is offline
Reply With Quote
View Public Profile
 
Old 04-11-2008, 01:56 PM Re: PHP code within HTML document
VirtuosiMedia's Avatar
Usability > SEO

Posts: 1,101
Trades: 0
Quote:
Originally Posted by Gilligan View Post
I use it, but mainly because I'm calling the page from inside 4 folders.

its better than doing ../../../../db.php

Easier editing, better knowing of where the files are. Just my opinion though.
It's fine if it's just your site, but if you're making scripts for other sites, make sure you change your code.
VirtuosiMedia is online now
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 04-11-2008, 07:27 PM Re: PHP code within HTML document
Gilligan's Avatar
Dead Like Me

Posts: 1,632
Name: Stefan
Location: London, UK
Trades: 0
Yeah, changed servers 3 times, and needed to update every file haha
__________________
DoThatDesign.com - Professional Website Design - FREE Quotes!
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 04-11-2008, 08:16 PM Re: PHP code within HTML document
tripy's Avatar
Do not try this at home!

Posts: 3,432
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
I've wondered though, what's the reason to use .inc.php rather than just .php for file names.
There is none.
I think that peoples just remember more easily that the file should be included when there is a .inc in the file name, but you could name it "file.ssdfjkghfkg" and it would not do any differences.

The .php is important though!
If you have DB connections infos (for example) in the file
PHP Code:
$db="secret";
$user="james_bond";
$password="007"
and the file has .php as extention, a direct request won't do nor display anything.
But, if the same file has a .inc extension, the PHP engine won't recognize it as a php file, and won't try to interpret it.
It will be displayed as is, in plain text, giving anyone accessing it the infos.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 04-11-2008 at 08:19 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 04-15-2008, 11:04 PM Re: PHP code within HTML document
Robert_R's Avatar
Skilled Talker

Posts: 88
Location: New Jersey
Trades: 0
Aw man. I can't get this sucker to work!
Robert_R is offline
Reply With Quote
View Public Profile
 
Old 04-16-2008, 07:02 AM Re: PHP code within HTML document
Gilligan's Avatar
Dead Like Me

Posts: 1,632
Name: Stefan
Location: London, UK
Trades: 0
What problem are you having?
__________________
DoThatDesign.com - Professional Website Design - FREE Quotes!
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 04-16-2008, 07:33 AM Re: PHP code within HTML document
Robert_R's Avatar
Skilled Talker

Posts: 88
Location: New Jersey
Trades: 0
I've put this line in the HTML code where I want execution and nothing shows.

<?php
include("index.php");
?>

The php includes HTML as well (countdown script)
Robert_R is offline
Reply With Quote
View Public Profile
 
Old 04-16-2008, 10:38 PM Re: PHP code within HTML document
Robert_R's Avatar
Skilled Talker

Posts: 88
Location: New Jersey
Trades: 0
Here's the HTML file. I've put the include code in bold.


HTML Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>Robert Raglievich</title>
	<link rel=stylesheet type="text/css" href="style.css">
    <script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
</head>

<body bottommargin="0" leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" topmargin="0" background="background.jpg" text="#EAF5FF">
<table width="100%" height="94" cellpadding="0" cellspacing="0" border="0">
	<tr valign="top">

		<td width="246" height="94"><img src="logo.jpg" width="246" height="94" border="0" alt=""></td>

		<td width="368" height="94"><img src="topbar1.jpg" width="368" height="94" border="0" alt=""></td>
		<td width="100%" height="94" background="topbar1bg.jpg">&nbsp;</td>
	</tr>
</table>
<table width="100%" height="91" cellpadding="0" cellspacing="0" border="0">
	<tr valign="top">
		<td width="613" height="91"><img src="2maincolorarea.jpg" width="613" height="91" border="0" alt=""></td>
		<td width="100%" height="91" background="2maincolorarea_bg.jpg">&nbsp;</td>
	</tr>
</table>
<table width="100%" height="33" cellpadding="0" cellspacing="0" border="0">
	<tr valign="top">
		<td width="246" height="33"><a href="index.html"><img src="home.jpg" width="207" height="33" border="0" alt=""></a></td>

		<td width="368" height="33"><img src="3buttonarea.jpg" width="427" height="33" border="0" alt=""></td>
		<td width="100%" height="33" background="3buttonareabg.jpg">&nbsp;</td>
	</tr>
</table>


<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<tr valign="top">

		<td width="207">

<a href="aboutme.html"><img src="aboutme.jpg" width="207" height="33" border="0" alt=""></a><BR>
<a href="http://www.robertraglievich.com/blog"><img src="bobbysblog.jpg" width="207" height="33" border="0" alt=""></a><BR>
<a href="portfolio.html"><img src="portfolio.jpg" width="207" height="33" border="0" alt=""></a><BR>
<a href="contactme.html"><img src="contactme.jpg" width="207" height="33" border="0" alt=""></a><BR>

<script type="text/javascript"><!--
google_ad_client = "pub-9006675163052100";
google_ad_width = 120;
google_ad_height = 240;
google_ad_format = "120x240_as";
google_ad_type = "text_image";
google_ad_channel = "";
google_color_border = "0000FF";
google_color_bg = "FFFFFF";
google_color_link = "0000FF";
google_color_text = "0000FF";
google_color_url = "0000FF";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>


		</td>
	
	
		<td width="20">&nbsp;&nbsp;&nbsp;</td>

		<td width="100%">

			<table width="100%" cellpadding="10" cellspacing="0" border="0">
				<tr valign="top">
					<td>			

<table width="100%" cellpadding="2" cellspacing="2" border="0"><tr valign="top">
<td width="49%">
<H3>Welcome to my site</h3>
<p align="justify">The Internet and the World Wide Web's popularity is increasing and growing larger everyday. Any business or individual can and should utilize it to send their message and reach virtually anyone, anytime, no matter where they are. The Internet has changed our lives in ways never imagined.</p>
<p align="justify"> We can get our news, sports, weather, and stock quotes without watching television, reading the newspaper or listening to the radio. We can buy, sell, and even browse without ever setting foot in a store. We can blog, chat, correspond, listen to music, learn, and work right from the comfort of our own homes.
<p align="justify">I've decided to create my own web site (again!). This time the emphasis will be career oriented. I'll do my best to give you a sense of my abilities, career goals, accomplishments, and future endeavors.</p>
<p>Thank you for visiting!</p>
</td>
</tr></table>
<H3>Dedication</h3>
<p align="justify">This website is dedicated to my wife Christine, who has never stopped believing in me and my abilities. Her presence and confidence has always been my inspiration. I love you more than words can express! ---- Bob</p>
<BR><BR><BR><BR><BR><BR><BR><BR><BR>
<BR><BR><BR><BR>

[bold]
<?php
include("index.php");
?> 
[/bold]

<a href="http://refer.asmallorange.com/Click/button/205"><img src="http://refer.asmallorange.com/Images/button7.png" /></a>
<a href="http://www.asmallorange.com" target="_blank"><img src="asmallorange.png" width="186" height="72" border="0"></a><br>
<script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','468','height','60','src','myfile','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','myfile' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="468" height="60">
  <param name="movie" value="myfile.swf">
  <param name="quality" value="high">
  <embed src="myfile.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="468" height="60"></embed>
</object>
</noscript><BR><BR><BR><BR><BR>
<center>Web site contents © Copyright Robert Raglievich 2007, All rights reserved.</center>


<center><a href="http://www.bobbyrags.com" title="Bobby Rags website" target="_blank">Bobby Rags</a></center>
					</td>
				</tr>
			</table>			
		</td>
		
		<td width="20">&nbsp;&nbsp;&nbsp;</td>
	</tr>
</table>

</body>
</html>
And here's the PHP code

PHP Code:
<?php
// Define your target date here
    
$targetYear  2008;
    
$targetMonth 09;
    
$targetDay   210
    $targetHour  
13;
    
$targetMinute00;
    
$targetSecond00;
// End target date definition

// Define date format
$dateFormat "Y-m-d H:i:s";

$targetDate mktime($targetHour,$targetMinute,$targetSecond,$targetMonth,$targetDay,$targetYear);
$actualDate time();

$secondsDiff $targetDate $actualDate;

$remainingDay     floor($secondsDiff/60/60/24);
$remainingHour    floor(($secondsDiff-($remainingDay*60*60*24))/60/60);
$remainingMinutes floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))/60);
$remainingSeconds floor(($secondsDiff-($remainingDay*60*60*24)-($remainingHour*60*60))-($remainingMinutes*60));

$targetDateDisplay date($dateFormat,$targetDate);
$actualDateDisplay date($dateFormat,$actualDate);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Max's Countdown System</title>
<link href="style/cntdwnstyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
  var days = <?php echo $remainingDay?>  
  var hours = <?php echo $remainingHour?>  
  var minutes = <?php echo $remainingMinutes?>  
  var seconds = <?php echo $remainingSeconds?>  

function setCountDown ()
{
  seconds--;
  if (seconds < 0){
      minutes--;
      seconds = 59
  }
  if (minutes < 0){
      hours--;
      minutes = 59
  }
  if (hours < 0){
      days--;
      hours = 23
  }
  document.getElementById("remain").innerHTML = days+" days, "+hours+" hours, "+minutes+" minutes, "+seconds+" seconds";
  setTimeout ( "setCountDown()", 1000 );
}

</script>
</head>

<body onload="setCountDown();">
<div id="container">
    <div id="header"><div id="header_left"></div>
    <div id="header_main">Max's Countdown System</div><div id="header_right"></div></div>
    <div id="content">
        <table class="countTable">
           <tr><td>Target date:</td><td><?php echo $targetDateDisplay?></td></tr>
           <tr><th colspan="2" id="remain"><?php echo "$remainingDay days, $remainingHour hours, $remainingMinutes minutes, $remainingSeconds seconds";?></th></tr>
           <tr><td>Actual date:</td><td><?php echo $actualDateDisplay?></td></tr>
       </table>
    </div>
    <div id="footer"><a href="http://www.phpf1.com" target="_blank">Powered by PHP F1</a></div>
</div>
</body>
</html>

Last edited by Robert_R; 04-16-2008 at 10:39 PM..
Robert_R is offline
Reply With Quote
View Public Profile
 
Old 04-16-2008, 11:26 PM Re: PHP code within HTML document
joder's Avatar
Flipotron

Posts: 6,441
Name: James
Location: In the ocean.
Trades: 0
If your running php and your .html file isn't displaying php, then apache isn't set up to.

Create a .htaccess file in your document root directory and add
Code:
AddHandler x-httpd-php .html .htm .php
joder is offline
Reply With Quote
View Public Profile
 
Old 04-17-2008, 09:52 AM Re: PHP code within HTML document
Gilligan's Avatar
Dead Like Me

Posts: 1,632
Name: Stefan
Location: London, UK
Trades: 0
or simply save you file as *.php

the file you're trying to include should be the countdown script, try saving that as countdown.php to avoid confusion.

so
page.php contains your html and this line where you want the countdown to appear
PHP Code:
<?php include('countdown.php'); ?>
and countdown.php contains your countdown script.

Also, as a note, bold should be [ b ] not [ bold ]
__________________
DoThatDesign.com - Professional Website Design - FREE Quotes!
Gilligan is offline
Reply With Quote
View Public Profile
 
Old 04-17-2008, 10:30 PM Re: PHP code within HTML document
Robert_R's Avatar
Skilled Talker

Posts: 88
Location: New Jersey
Trades: 0
Quote:
Originally Posted by Gilligan View Post
or simply save you file as *.php

the file you're trying to include should be the countdown script, try saving that as countdown.php to avoid confusion.

so
page.php contains your html and this line where you want the countdown to appear
PHP Code:
<?php include('countdown.php'); ?>
and countdown.php contains your countdown script.

Also, as a note, bold should be [ b ] not [ bold ]
The HTML "within" the countdown script becomes page.php

or

are you referring to the main page HTML to become page.php?
Robert_R is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP code within HTML document
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 


Page generated in 0.16772 seconds with 13 queries