Documente Academic
Documente Profesional
Documente Cultură
$var=mysql_connect(host,username,passw
ord,portnumber);
mysql_select_db(dbname,connect variable);
$result=mysql_query(querystring);
$row=mysql_fetch_row($result);
$row=mysql_fetch_array($result,MYSQL_AS
SOC);
$recordcount=mysql_num_rows($result);
STRING HANDLING
str_repeat(string,repeat)- repeats a string a specified number of
times.
<?php
echo str_repeat(".",13);
?>
<?php
echo str_replace("world","Peter","Hello world!");
?>
<?php
$arr = array("blue","red","green","yellow");
print_r(str_replace("red","pink",$arr,$i));
echo "Replacements: $i";
?>
strcmp(string1,string2) - compares two strings.
0 - if the two strings are equal
0 - if string1 is less than string2
0 - if string1 is greater than string2
<?php echo strcmp("Hello world!","Hello world!"); ?>
strlen(string) - returns the length of a string.
strtolower(string) - converts a string to lowercase.
strtoupper(string) - converts a string to uppercase
ucfirst(string) - converts the first character of a string to uppercase.
ucwords(string) - converts the first character of each word in a
string to uppercase.
strpos(string,find,start) - returns the position of the first occurrence
of a string inside another string.
$str = 'test string';
$sub_str = 'str';
if (strpos($str, $sub_str) === false)
echo "Substring not found";
else
echo "Substring exist in given string";
UI
<FORM ACTION="welcome.php"
METHOD=GET>
First Name: <INPUT TYPE=TEXT
NAME="firstname"><BR>
Last Name: <INPUT TYPE=TEXT
NAME="lastname">
<INPUT TYPE=SUBMIT VALUE="GO">
</FORM>
FORM PROCESSING
<?php
$firstname=$_GET['firstname'];
$lastname = $_GET['lastname'];
echo( "Welcome to our Web site,
$firstname $lastname!" );
?>
PUBLISHING MySQL DATA
<HTML>
<HEAD>
<TITLE> Our List of Jokes </TITLE>
<HEAD>
<BODY>
<?php
?>
<P> Here are all the jokes in our database: </P>
<BLOCKQUOTE>
<?php
?>
INSERTING DATA TO MySQL
<FORM ACTION="<?php echo($PHP_SELF); ?>" METHOD=POST>
<P>Type your joke here:<BR>
<TEXTAREA NAME="joketext" ROWS=10 COLS=40 WRAP></TEXTAREA><BR>
<INPUT TYPE=SUBMIT NAME="submitjoke" VALUE="SUBMIT">
</FORM>
<?php
$joketext=$_POST['joketext'];
$submitjoke=$_POST['submitjoke'];
$dbcnx = @mysql_connect("localhost",
"root", "mypasswd");
if (!$dbcnx) {
echo( "<P>Unable to connect to the " .
"database server at this time.</P>" );
exit();
}
if (isset($_POST['deletejoke'])) {
$sql = "DELETE FROM Jokes " .
"WHERE ID=$deletejoke";
if (mysql_query($sql)) {
echo("<P>The joke has been deleted.</P>");
} else {
echo("<P>Error deleting joke: " .
mysql_error() . "</P>");
}
}
SESSIONS
<p>
To continue, <a href="nextpage.php?<?php echo
htmlspecialchars(session_id()); ?>">click
here</a>.
</p>
SESSION LOGIN
<?php
session_start();
$_SESSION['active']=false;
$_SESSION['uname']=false;
if (! $_SESSION[active]) {
$_SESSION[active] = 1;
$heading = "Welcome - please log in";
$htmlsay = "Please enter your name <input name=whoareyou><input
type=submit>";
}
/*
else
{
if (! $_SESSION['uname'] && ($_POST['whoareyou'])) {
$_SESSION['uname'] = $_POST['whoareyou'];
}
}
*/
?>
<html>
<head></head>
<body>
<form method=post action="<?php echo $PHP_SELF;?>">
<?php echo $htmlsay;?>
</form>
</body>
</html>
<?php
if(isset($_SESSION['active']))
{
if(isset($_POST['whoareyou'])
{
$_SESSION['uname']=$_POST['whoareyou'];
print “<a href='welcome.php'>Continue</a>”;
}
}
?>
<html>
<head></head>
<body>
<?php
sssion_start()
IF($_SESSION['uname']==”baskar”)
{
print “Welcome Mr.”.$_SESSION['uname'];
}
else
{
print “You are not authorised to view this page”;
}
?>
</body>
</html>
HTTP
After sending the header and the blank line, the client
transmits the data. The header must have included a
Content-Length: field, which permits the server to
determine when all the data has been received.
INSTALLING APACHE
Windows
1. Download XAMPP from apachefriends.org
2. unzip it under C:\
Linux
1. All recent distributions comes with apache.
2. Choose Web Server under Server while installing
OR
3. After installing linux, go to Add/Remove choose apache and install
OR
4. Download the tarball from apache.org and install using the following
steps
unzip and untar the tarball. You should get a new directory with the
name apache-2.x under the present directory.
Descend to the new directory and type
configure
make
as a root type 'make install'
CONFIGURING APACHE
cd /etc/apache2/sites-enabled
ln -s /etc/apache2/sites-available/example.com.conf
example.com.conf
In other distributions
Simply add the following lines to httpd.conf
NameVirtualHost *
<VirtualHost *>
ServerName www.domain.tld
DocumentRoot /www/domain
ServerAlias domain.tld *.domain.tld
</VirtualHost>
Listen 10.1.2.3:80
Listen 10.1.2.4:8000
<VirtualHost 10.1.2.3>
DocumentRoot /www/vhost1
ServerName www.my-dom.com
</VirtualHost>
MONITORING
<Location /server-status>
SetHandler server-status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
HTTP://127.0.0.1/server-status
You could be using localhost instead of 127.0.0.1, but keep
in mind that if the directive HostnameLookups is turned to
Off, apache won't let you access to
http://localhost/server-status
THANK YOU
By
BASKAR. K
9940024492
baskar_k@sify.com