Worth2Read
Home

Forum

PHP Tutorials
Blogs
Children
Article Directory

Contact Us

Disclaimer
Reliable $1 Web Hosting by 3iX
 

 

If you have any doubts with your PHP code please discuss it in the PHP Forum

Php Syntax:

<?php

----

?>


Including an html or php file in another php file

<?php include("header.html"); ?>

<?php include("header.html"); ?>


Code To determine the number of hits in your website :

1.Create a .txt file, say hit.txt.

2. Enter the value 0 in hit.txt and save.

3. Create a php file, say counter.php with the following code...

 

<?php

$filename= "hits.txt" ;

$fd = fopen ($filename , "r") or die ("Can't open $filename") ;

$fstring = fread ($fd , filesize ($filename)) ;

echo "$fstring" ;

fclose($fd) ;

$fd = fopen ($filename , "w") or die ("Can't open $filename") ;

$fhits = $fstring + 1 ;

$fout= fwrite ($fd , $fhits ) ;

fclose($fd) ;

?>

4. Include the counter.php file wherever you want to display the number of hits.


Print Date

<? print(Date("l F d, Y")); ?>


Sending Email using PHP

contactus.html

<html>

<body>

<form method="post" action="thankyou.php">

Your Name:
<input type="text" name="name" />
</p>
<p><br />
Your Email:
<input type="text" name="email" />
<br />


Mail Message:

<textarea name="comments" rows="5" cols="45"></textarea>
</p>
<p><br />
<input type="submit" value="Send Mail" />
</p>

</form>

</body>

</html>

thankyou.php

<?php

$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];

$todayis = date("l, F j, Y, g:i a") ;

$subject = "Message From my site";

$comments = stripcslashes($comments);

$message = " $todayis [EST] \n

Message: $comments \n
From: $name ($email)\n
";

$from = "From: $email\r\n";

mail("reachme@worth2read.org", $subject, $message, $from);

?>

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

Replace reachme@worth2read.org with the mail id you want to receive the email.

It is worth noting that the mail() function is not suitable for larger volumes of email in a loop(ie sending newsletters by accessing mail id from database). This function opens and closes an SMTP socket for each email, which is not very efficient.
For the sending of large amounts of email, see the » PEAR::Mail, and PEAR::Mail_Queue packages.


Code to capture IP address

$ipaddress = getenv("REMOTE_ADDR"); ?>

<?php echo $ipi; ?>

Copyright © 2008 www.worth2read.org. All rights Reserved. Use of this Site is subject to our Privacy Statement
Untitled Document
PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide
Programming PHP
Beginning PHP and MySQL: From Novice to Professional, Third Edition (Beginning from Novice to Professional)
Wicked Cool PHP: Real-World Scripts That Solve Difficult Problems
PHP and MySQL Web Development (3rd Edition) (Developer's Library)
PHP & MySQL For Dummies 3rd edition (For Dummies (Computer/Tech))
PHP Solutions: Dynamic Web Design Made Easy (Solutions)
Build Your Own Website The Right Way Using HTML & CSS
Learning Web Design: A Beginner's Guide to (X)HTML, StyleSheets, and Web Graphics
Sams Teach Yourself HTML and CSS in 24 Hours (7th Edition) (Sams Teach Yourself)