one can install php in redhat/fedora series by using yum
#yum install php
#yum install php-mysql
next restart/start your webserver to see the effect
for restart:~~
/etc/init.d/httpd restart
for start:~~
/etc/init.d/httpd start
Next create a page in /var/www/html/
#echo '' > /var/www/html/testphp.php
Now access this page through
http://localhost/testphp.php
voila!your php is now installed.
example of some php'ing:~
~~~~~~/var/www/html/form.html~~~~~~~~~~~~~~~~~~~
<form method="post" action="sendmail.php">
Email: <input name="email" type="text" /><br />
Message:<br />
<textarea name="message" rows="15" cols="40">
</textarea><br />
<input type="submit" />
</form>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~~~~~/var/www/html/sendmail.php~~~~~~~~~~~~~~~~~~~~~
<?
$email= $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
if (!isset($_REQUEST['email'])) {
header( "Location: http://localhost/form.html" );
}
elseif (empty($email) || empty($message)) {
?>
<html>
<head><title>Error</title></head>
<body>
<h1>Error</h1>
<p>
Oops, it appears you forgot to enter either your
email address or your message. Please press the BACK
button in your browser and try again.
</p>
</body>
</html>
<?
}
else {
mail( "crenshaw_jo@yahoo.com", "Feedback Form Results",
$message, "From: $email" );
header( "Location: http://localhost/thankyou.html" );
}
?>
~~~~~~~~~~~~~/var/www/html/thankyou.html~~~~~~~~~~~~~~~~~
<html>
<body>
Thank you.Have a nice day!
</body>
</html>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
We access form.html using the link
http://localhost/form.html
It opens a webpage in browser window which asks for email id and a message.On clicking submit button,it goes to sendmail.php,where
the message and email are stored into variables called message and email respectively.[notice the $ sign before the variable].
$_REQUEST['message'] is almost like the getrequest function of jsp.
The isset function is used to prevent users from accessing sendmail.php from the browser window itself accessing http://localhost/sendmail.php.
One can incorporate an html page inside the php page,like the error message here.
mail is a function whose first parameter is the mail of the receiver.Second parameter is the subject.Third parameter is the
content of the message.Fourth parameter is the headers of the message.
The header function redirects to the given webpage.
|