mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-15 16:38:54 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@205034 c90b9560-bf6c-de11-be94-00142212c4b1
524 lines
23 KiB
XML
524 lines
23 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
||
<!-- $Revision: 1.40 $ -->
|
||
<chapter id="tutorial">
|
||
<title>A simple tutorial</title>
|
||
|
||
<para>
|
||
Here we would like to show the very basics of PHP in a short, simple
|
||
tutorial. This text only deals with dynamic webpage creation with
|
||
PHP, though PHP is not only capable of creating webpages. See
|
||
the section titled <link linkend="intro-whatcando">What can PHP
|
||
do</link> for more information.
|
||
</para>
|
||
<para>
|
||
PHP-enabled web pages are treated just like regular HTML pages and
|
||
you can create and edit them the same way you normally create
|
||
regular HTML pages.
|
||
</para>
|
||
|
||
<sect1 id="tutorial.requirements">
|
||
<title>What do I need?</title>
|
||
<para>
|
||
In this tutorial we assume that your server has activated support
|
||
for PHP and that all files ending in <filename>.php</filename>
|
||
are handled by PHP. On most servers, this is the default extension
|
||
for PHP files, but ask your server administrator to be sure. If
|
||
your server supports PHP, then you do not need to do anything. Just
|
||
create your <filename>.php</filename> files, put them in your
|
||
web directory and the server will automatically parse them for you.
|
||
There is no need to compile anything nor do you need to install
|
||
any extra tools. Think of these PHP-enabled files as simple HTML
|
||
files with a whole new family of magical tags that let you do all
|
||
sorts of things. Most web hosts offer PHP support, but if your
|
||
host does not, consider reading the <ulink url="&url.php.links;">
|
||
PHP Links</ulink> section for resources on finding PHP enabled
|
||
web hosts.
|
||
</para>
|
||
<para>
|
||
Let us say you want to save precious bandwidth and develop locally.
|
||
In this case, you will want to install a web server, such as
|
||
<ulink url="&url.apache;">Apache</ulink>, and of course
|
||
<ulink url="&url.php.downloads;">PHP</ulink>. You will most likely
|
||
want to install a database as well, such as
|
||
<ulink url="&url.mysql.docs;">MySQL</ulink>.
|
||
</para>
|
||
<para>
|
||
You can either install these individually or choose a simpler way. Our
|
||
manual has <link linkend="install">installation instructions for
|
||
PHP</link> (assuming you already have some webserver set up). In case
|
||
you have problems with installing PHP yourself, we would suggest you ask
|
||
your questions on our <ulink url="&url.php.mailing-lists;">installation
|
||
mailing list</ulink>. If you choose to go on the simpler route, then
|
||
<ulink url="&url.installkits;">locate a pre-configured package</ulink>
|
||
for your operating system, which automatically installs all of these
|
||
with just a few mouse clicks. It is easy to setup a web server with PHP
|
||
support on any operating system, including MacOSX, Linux and Windows.
|
||
On Linux, you may find <ulink url="&url.rpmfind;">rpmfind</ulink> and
|
||
<ulink url="&url.rpmfind.pbone;">PBone</ulink> helpful for
|
||
locating RPMs. You may also want to visit <ulink
|
||
url="&url.apt-get;">apt-get</ulink> to find packages for Debian.
|
||
</para>
|
||
</sect1>
|
||
|
||
<sect1 id="tutorial.firstpage">
|
||
<title>Your first PHP-enabled page</title>
|
||
<para>
|
||
Create a file named <filename>hello.php</filename> and put it
|
||
in your web server's root directory (<varname>DOCUMENT_ROOT</varname>)
|
||
with the following content:
|
||
</para>
|
||
<para>
|
||
<example>
|
||
<title>Our first PHP script: <filename>hello.php</filename></title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<html>
|
||
<head>
|
||
<title>PHP Test</title>
|
||
</head>
|
||
<body>
|
||
<?php echo '<p>Hello World</p>'; ?>
|
||
</body>
|
||
</html>
|
||
]]>
|
||
</programlisting>
|
||
<simpara>
|
||
Use your browser to access the file with your web server's URL, ending
|
||
with the "/hello.php" file reference. When developing locally this
|
||
URL will be something like <literal>http://localhost/hello.php</literal>
|
||
or <literal>http://127.0.0.1/hello.php</literal> but this depends on the
|
||
web server's configuration. If everything is configured correctly, this
|
||
file will be parsed by PHP and the following output will be sent to
|
||
your browser:
|
||
</simpara>
|
||
<screen role="html">
|
||
<![CDATA[
|
||
<html>
|
||
<head>
|
||
<title>PHP Test</title>
|
||
</head>
|
||
<body>
|
||
<p>Hello World</p>
|
||
</body>
|
||
</html>
|
||
]]>
|
||
</screen>
|
||
</example>
|
||
</para>
|
||
<para>
|
||
This program is extremely simple and you really did not need to use
|
||
PHP to create a page like this. All it does is display:
|
||
<literal>Hello World</literal> using the PHP <function>echo</function>
|
||
statement. Note that the file <emphasis>does not need to be executable</emphasis>
|
||
or special in any way. The server finds out that this file needs to be interpreted
|
||
by PHP because you used the ".php" extension, which the server is configured
|
||
to pass on to PHP. Think of this as a normal HTML file which happens to have
|
||
a set of special tags available to you that do a lot of interesting things.
|
||
</para>
|
||
<para>
|
||
If you tried this example and it did not output anything, it prompted
|
||
for download, or you see the whole file as text, chances are that the
|
||
server you are on does not have PHP enabled, or is not configured properly.
|
||
Ask your administrator to enable it for you using the
|
||
<link linkend="install">Installation</link> chapter
|
||
of the manual. If you are developing locally, also read the
|
||
installation chapter to make sure everything is configured
|
||
properly. Make sure that you access the file via http with the server
|
||
providing you the output. If you just call up the file from your file
|
||
system, then it will not be parsed by PHP. If the problems persist anyway,
|
||
do not hesitate to use one of the many
|
||
<ulink url="&url.php.support;">PHP support</ulink> options.
|
||
</para>
|
||
<para>
|
||
The point of the example is to show the special PHP tag format.
|
||
In this example we used <literal><?php</literal> to indicate the
|
||
start of a PHP tag. Then we put the PHP statement and left PHP mode by
|
||
adding the closing tag, <literal>?></literal>. You may jump in
|
||
and out of PHP mode in an HTML file like this anywhere you want. For more
|
||
details, read the manual section on the <link linkend="language.basic-syntax">
|
||
basic PHP syntax</link>.
|
||
</para>
|
||
|
||
<note>
|
||
<title>A Note on Text Editors</title>
|
||
<para>
|
||
There are many text editors and Integrated Development Environments (IDEs)
|
||
that you can use to create, edit and manage PHP files. A partial list of
|
||
these tools is maintained at <ulink url="&url.phpeditorlist;">PHP Editors
|
||
List</ulink>. If you wish to recommend an editor, please visit the above
|
||
page and ask the page maintainer to add the editor to the list. Having
|
||
an editor with syntax highlighting can be helpful.
|
||
</para>
|
||
</note>
|
||
|
||
<note>
|
||
<title>A Note on Word Processors</title>
|
||
<para>
|
||
Word processors such as StarOffice Writer, Microsoft Word and Abiword are
|
||
not optimal for editing PHP files. If you wish to use one for this
|
||
test script, you must ensure that you save the file as <emphasis>plain
|
||
text</emphasis> or PHP will not be able to read and execute the script.
|
||
</para>
|
||
</note>
|
||
|
||
<note>
|
||
<title>A Note on Windows Notepad</title>
|
||
<para>
|
||
<<<<<<< tutorial.xml
|
||
PHP betiklerinizi Windows Not Defteri ile yaz<EFBFBD>yorsan<EFBFBD>z, dosyalar<EFBFBD>n<EFBFBD>z<EFBFBD>n .php uzant<EFBFBD>s<EFBFBD>
|
||
ile kaydedildi<EFBFBD>inden emin olmal<EFBFBD>s<EFBFBD>n<EFBFBD>z (Notepad birazdan bahsedece<EFBFBD>imiz <EFBFBD>nlemleri
|
||
almad<EFBFBD><EFBFBD><EFBFBD>n<EFBFBD>z takdirde dosyalar<EFBFBD>n sonuna otomatik olarak .txt uzant<EFBFBD>s<EFBFBD> ekler).
|
||
Dosyay<EFBFBD> kaydetmek istedi<EFBFBD>inizde, sizden dosyan<EFBFBD>z i<EFBFBD>in bir isim belirtmeniz istenecektir.
|
||
Dosya ismi olarak t<EFBFBD>rnak i<EFBFBD>inde (<EFBFBD>rn. "<filename>hello.php</filename>") yaz<61>n.
|
||
Alternatif olarak, 'Kaydet' ileti<74>im kutusunun i<>indeki 'Metin Belgeleri' a<><61>l<EFBFBD>r men<65>s<EFBFBD>ne
|
||
t<>klad<61>ktan sonra buradaki de<64>eri "T<>m Dosyalar" olarak de<64>i<EFBFBD>tirin. Art<72>k dosya isminizi
|
||
t<>rnak i<>areti kullanmadan yazabilirsiniz.
|
||
=======
|
||
If you are writing your PHP scripts using Windows Notepad, you will need
|
||
to ensure that your files are saved with the .php extension. (Notepad adds
|
||
a .txt extension to files automatically unless you take one of the
|
||
following steps to prevent it.) When you save the file and are prompted
|
||
to provide a name for the file, place the filename in quotes
|
||
(i.e. "<filename>hello.php</filename>"). Alternatively, you can click on the
|
||
'Text Documents' drop-down menu in the 'Save' dialog box and change the setting
|
||
to "All Files". You can then enter your filename without quotes.
|
||
>>>>>>> 1.39
|
||
</para>
|
||
</note>
|
||
|
||
<para>
|
||
Art<72>k <20>al<61><6C><EFBFBD>r bir PHP beti<74>ini ba<62>ar<61>yla yaratt<74><74><EFBFBD>n<EFBFBD>za g<>re, PHP betiklerinin
|
||
en <20>nl<6E>s<EFBFBD>n<EFBFBD> yaratma zaman<61> geldi demektir! <function>Phpinfo</function>
|
||
fonksiyonunu <20>al<61><6C>t<EFBFBD>raca<63><61>z ve sisteminizle ve yap<61>land<6E>rman<61>zla ilgili
|
||
<link linkend="language.variables.predefined"><EFBFBD>ntan<EFBFBD>ml<EFBFBD> de<64>i<EFBFBD>kenler</link>,
|
||
y<>kl<6B> PHP mod<6F>lleri ve <link linkend="configuration">yap<EFBFBD>land<EFBFBD>rma</link>
|
||
ayarlar<61> gibi konularda faydal<61> bir<69>ok bilgiye ula<6C>aca<63><61>z. Bu <20>nemli bilgiler i<>in
|
||
biraz vakit ay<61>rman<61>z<EFBFBD> ve bunlar<61> incelemenizi <20>neririz.
|
||
</para>
|
||
<para>
|
||
<example>
|
||
<title>PHP ile sistem bilgisine ula<6C>mak</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<?php phpinfo(); ?>
|
||
]]>
|
||
</programlisting>
|
||
</example>
|
||
</para>
|
||
</sect1>
|
||
|
||
<sect1 id="tutorial.useful">
|
||
<title><EFBFBD><EFBFBD>e yarar bir <20>ey</title>
|
||
<para>
|
||
<20>imdi daha i<>e yarar bir <20>ey yapal<61>m. Kullan<61>c<EFBFBD>n<EFBFBD>z<EFBFBD>n hangi taray<61>c<EFBFBD>y<EFBFBD>
|
||
kulland<6E><64><EFBFBD>n<EFBFBD> tespit edelim. Bunun i<>in, HHTP iste<74>i ile birlikte kullan<61>c<EFBFBD>n<EFBFBD>z<EFBFBD>n
|
||
taray<61>c<EFBFBD> taraf<61>ndan g<>nderilen karakter dizisi (string) de<64>erini inceleyece<63>iz.
|
||
Bu de<64>er bir <link linkend="language.variables">de<EFBFBD>i<EFBFBD>ken</link> i<>inde
|
||
depolanm<6E><6D>t<EFBFBD>r. De<44>i<EFBFBD>kenler PHP'de her zaman dolar i<>areti ile ba<62>lar.
|
||
Bizim <20>u an i<>in ilgilendi<64>imiz de<64>i<EFBFBD>ken <varname>$_SERVER['HTTP_USER_AGENT']</varname>
|
||
de<64>i<EFBFBD>kenidir.
|
||
</para>
|
||
<note>
|
||
<para>
|
||
<link linkend="reserved.variables.server">$_SERVER</link> <20>zel saklanm<6E><6D>
|
||
bir PHP de<64>i<EFBFBD>kenidir. Bu de<64>i<EFBFBD>ken t<>m web sunucusu bilgilerini i<>erir. Autoglobal
|
||
(ya da superglobal - s<>per evrensel) olarak da bilinir. K<>lavuzdaki
|
||
<link linkend="language.variables.superglobals">Superglobals</link>
|
||
b<>l<EFBFBD>m<EFBFBD>nden bu konu ile ilgili daha fazla bilgiye ula<6C>abilirsiniz. Bu <20>zel de<64>i<EFBFBD>kenler
|
||
PHP <ulink url="&url.php.release4.1.0;">4.1.0</ulink> s<>r<EFBFBD>m<EFBFBD> ile birlikte
|
||
kullan<61>lmaya ba<62>lanm<6E><6D>t<EFBFBD>r. Daha <20>ncesinde, <varname>$HTTP_SERVER_VARS</varname>
|
||
gibi eski <varname>$HTTP_*_VARS</varname> dizileri (array) kullan<61>lmaktayd<79>.
|
||
<20>mr<6D>n<EFBFBD> doldurmu<6D> olsa da, bu eski tip de<64>i<EFBFBD>kenler hala mevcuttur. (<link linkend="tutorial.oldcode">Eski kod</link>
|
||
b<>l<EFBFBD>m<EFBFBD>ne de bak<61>n<EFBFBD>z.)
|
||
</para>
|
||
</note>
|
||
<para>
|
||
Bu de<64>i<EFBFBD>keni g<>r<EFBFBD>nt<6E>lemek i<>in yapman<61>z gereken basit<69>e:
|
||
</para>
|
||
<para>
|
||
<example>
|
||
<title>Bir de<64>i<EFBFBD>keni yazd<7A>rmak (Dizi <20><>esi)</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<?php echo $_SERVER['HTTP_USER_AGENT']; ?>
|
||
]]>
|
||
</programlisting>
|
||
<para>
|
||
Bu betikten al<61>nabilecek k<>sa sonu<6E>:
|
||
</para>
|
||
<screen role="html">
|
||
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)
|
||
</screen>
|
||
</example>
|
||
</para>
|
||
<para>
|
||
PHP' bir<69>ok farkl<6B> de<64>i<EFBFBD>ken <link linkend="language.types">tipi</link>
|
||
mevcuttur. Yukardaki <20>rnekte bir <link linkend="language.types.array">dizi</link>ye
|
||
ait bir <20><>eyi yazd<7A>rd<72>k. Diziler <20>ok kullan<61><6E>l<EFBFBD> olabilirler.
|
||
</para>
|
||
<para>
|
||
<varname>$_SERVER</varname> size PHP taraf<61>ndan otomatik olarak sa<73>lanan
|
||
bir de<64>i<EFBFBD>kendir. Kullan<61>m k<>lavuzunun
|
||
<link linkend="reserved.variables">Rezerve De<44>i<EFBFBD>kenler</link> b<>l<EFBFBD>m<EFBFBD>nden
|
||
t<>m<EFBFBD>n<EFBFBD>n bir listesine ula<6C>abilirsiniz ya da <20>nceki <20>rnekte kulland<6E><64><EFBFBD>m<EFBFBD>z
|
||
<function>phpinfo</function> fonksiyonu ile <20>retilen <20><>kt<6B>ya bakarak b<>t<EFBFBD>n
|
||
listeye ula<6C>abilirsiniz.
|
||
</para>
|
||
<para>
|
||
PHP etiketinin i<>ine birden <20>ok PHP komutu koyabilir ve tek bir echo komutundan
|
||
daha fazlas<61>n<EFBFBD> yapan k<><6B><EFBFBD>k kod bloklar<61> yaratabilirsiniz. <20>rne<6E>in, Internet Explorer i<>in
|
||
bir kontrol yapmak istiyorsan<61>z <20>unu yapabilirsiniz:
|
||
</para>
|
||
<para>
|
||
<example>
|
||
<title><link linkend="language.control-structures">Kontrol yap<61>lar<61>
|
||
</link>n<EFBFBD>n ve <link linkend="language.functions">fonksiyonlar</link><EFBFBD>n kullan<61>m<EFBFBD>na <20>rnek</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<?php
|
||
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
|
||
echo 'Internet Explorer kullanmaktas<61>n<EFBFBD>z.<br />';
|
||
}
|
||
?>
|
||
]]>
|
||
</programlisting>
|
||
<para>
|
||
Bu betikten al<61>nabilecek <20>rnek sonu<6E>:
|
||
</para>
|
||
<screen role="html">
|
||
<![CDATA[
|
||
Internet Explorer kullan<61>yorsunuz.<br />
|
||
]]>
|
||
</screen>
|
||
</example>
|
||
</para>
|
||
<para>
|
||
Nurada birka<6B> yeni kavram<61> devreye soktuk. Bir <link linkend="control-structures.if">if</link>
|
||
komutumuz var. E<>er C dilinde kullan<61>lan temel s<>zdizimine a<>inal<61><6C><EFBFBD>n<EFBFBD>z varsa, bu kullan<61>m
|
||
size tan<61>d<EFBFBD>k gelecektir. Aksi takdirde, giri<72> d<>zeyinde bir PHP kitab<61> alman<61>z ve ilk birka<6B> b<>l<EFBFBD>m<EFBFBD>n<EFBFBD>
|
||
okuman<61>z ya da k<>lavuzun <link linkend="langref">Dil Ba<42>vuru Kayna<6E><61></link> b<>l<EFBFBD>m<EFBFBD>n<EFBFBD>
|
||
okuman<61>z faydal<61> olacakt<6B>r. PHP kitaplar<61>n<EFBFBD>n bir listesine <ulink url="&url.php.books;">&url.php.books;</ulink>
|
||
adresinden ula<6C>abilirsiniz.
|
||
</para>
|
||
<para>
|
||
<20>kinci devreye ald<6C><64><EFBFBD>m<EFBFBD>z kavram <function>strpos</function> fonksiyonu ile yapt<70><74><EFBFBD>m<EFBFBD>z <20>a<EFBFBD>r<EFBFBD> oldu.
|
||
<function>Strpos</function> fonksiyonu PHP i<>ine yerle<6C>ik olan, bir karakter dizisini di<64>er karakter dizisinin
|
||
i<>inde aramay<61> sa<73>layan bir fonksiyondur. Kendi durumumuzda biz <varname>$_SERVER['HTTP_USER_AGENT']</varname>
|
||
(haystack - aramaya konu olan par<61>a olarak da adland<6E>r<EFBFBD>l<EFBFBD>r) de<64>i<EFBFBD>keni i<>ersinde <literal>'MSIE'</literal> (needle - aranan par<61>a olarak da adland<6E>r<EFBFBD>l<EFBFBD>r)
|
||
par<61>as<61>n<EFBFBD> aratmaktay<61>z. Aranan par<61>a, aramaya konu olan par<61>a i<>inde bulunursa, fonksiyon aramaya konu olan par<61>an<61>n ba<62>lang<6E><67> noktas<61>na
|
||
g<>receli olarak aranan par<61>an<61>n bulundu<64>u noktan<61>n yerini d<>nd<6E>r<EFBFBD>r. Aksi durumda, &false; d<>nd<6E>r<EFBFBD>r. &false; d<>nd<6E>rmezse,
|
||
<link linkend="control-structures.if">if</link> komutunun sonucu &true; olarak de<64>erlendirilir ve {k<><6B>eli parantezler} i<>indeki kod <20>al<61><6C>t<EFBFBD>r<EFBFBD>l<EFBFBD>r.
|
||
Aksi durumda kod <20>al<61><6C>t<EFBFBD>r<EFBFBD>lmaz. <link linkend="control-structures.if">If</link>, <link linkend="control-structures.else">else</link> gibi
|
||
kontrol yap<61>lar<61>n<EFBFBD>n ve <function>strtoupper</function> ve <function>strlen</function> gibi fonksiyonlar<61>n kullanarak siz kendiniz de benzer
|
||
<20>rnekler yaratabilirsiniz. <20>lgili her k<>lavuz sayfas<61> ayn<79> zamanda <20>rnekler de i<>ermektedir. Bu fonksiyonlar<61> nas<61>l kullanman<61>z gerekti<74>inden
|
||
emin de<64>ilseniz, k<>lavuzdaki <link linkend="about.prototypes">bir fonksiyon tan<61>m<EFBFBD> nas<61>l okunur</link> ve <link linkend="language.functions">PHP fonksiyonlar<61></link>
|
||
b<>l<EFBFBD>mlerini okuyabilirsiniz.
|
||
</para>
|
||
<para>
|
||
Bunu bir ad<61>m <20>teye ta<74><61>yabilir ve bir PHP blo<6C>unun tam ortas<61>ndayken bile PHP kipine nas<61>l girip <20><>kabilece<63>imize bakabiliriz:
|
||
</para>
|
||
<para>
|
||
<example>
|
||
<title>HTML ve PHP kiplerini kar<61><72>t<EFBFBD>rmak</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
<?php
|
||
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
|
||
?>
|
||
<h3>strpos() false olmayan bir de<64>er d<>nd<6E>rmelidir</h3>
|
||
<p>Internet Explorer kullanmaktas<61>n<EFBFBD>z</p>
|
||
<?php
|
||
} else {
|
||
?>
|
||
<h3>strpos() false d<>nd<6E>rmelidir</h3>
|
||
<p>Internet Explorer kullanm<6E>yorsunuz</p>
|
||
<?php
|
||
}
|
||
?>
|
||
]]>
|
||
</programlisting>
|
||
<para>
|
||
Bu betikten elde edilebilecek <20>rnek sonu<6E>:
|
||
</para>
|
||
<screen role="html">
|
||
<![CDATA[
|
||
<h3>strpos() false olmayan bir de<64>er d<>nd<6E>rmelidir</h3>
|
||
<p>Internet Explorer kullan<61>yorsunuz</p>
|
||
]]>
|
||
</screen>
|
||
</example>
|
||
</para>
|
||
<para>
|
||
Bir <20><>kt<6B> <20>retmek i<>in PHP echo komutunu kullanmak yerine, PHP kipinden
|
||
<20><>kt<6B>k ve sadece d<>z HTML g<>nderdik. Burada dikkat edilmesi gereken <20>nemli
|
||
nokta, beti<74>in mant<6E>ksal ak<61><6B><EFBFBD>n<EFBFBD>n de<64>i<EFBFBD>miyor olmas<61>d<EFBFBD>r. <function>Strpos</function>
|
||
fonksiyonundan edinilen sonuca g<>re HTML bloklar<61>ndan yaln<6C>zca biri g<>r<EFBFBD>nt<6E>leyiciye
|
||
g<>nderilmektedir. Ba<42>ka bir deyi<79>le, bu i<>leyi<79> <literal>MSIE</literal> de<64>i<EFBFBD>keninin
|
||
bulunup bulunmamas<61>na ba<62>l<EFBFBD>d<EFBFBD>r.
|
||
</para>
|
||
</sect1>
|
||
|
||
<sect1 id="tutorial.forms">
|
||
<title>Form Kullan<61>m<EFBFBD></title>
|
||
<para>
|
||
PHP'nin en g<><67>l<EFBFBD> <20>zelliklerinden biri HTML formlar<61>na yakla<6C><61>m bi<62>imidir.
|
||
Bilinmesi gereken ilk <20>nemli durum, form i<>indeki t<>m elemanlar PHP taraf<61>ndan
|
||
otomatik olarak kullan<61>labilir olacakt<6B>r. Bu konu ile ilgili k<>lavuzdaki
|
||
<link linkend="language.variables.external">PHP'nin d<><64><EFBFBD>ndan gelen
|
||
de<64>i<EFBFBD>kenler</link> b<>l<EFBFBD>m<EFBFBD>n<EFBFBD> okuyabilirsiniz. <20>rnek bir HTML formu:
|
||
</para>
|
||
<para>
|
||
<example>
|
||
<title><EFBFBD>rnek bir HTML formu</title>
|
||
<programlisting role="html">
|
||
<![CDATA[
|
||
<form action="action.php" method="post">
|
||
<p><3E>sminiz: <input type="text" name="isim" /></p>
|
||
<p>Ya<59><61>n<EFBFBD>z: <input type="text" name="yas" /></p>
|
||
<p><input type="submit" /></p>
|
||
</form>
|
||
]]>
|
||
</programlisting>
|
||
</example>
|
||
</para>
|
||
<para>
|
||
Bu form ile ilgili <20>zel hi<68>bir <20>ey yoktur. Hi<48>bir <20>zel etiket i<>ermeyen d<>z bir
|
||
HTML formudur. Kullan<61>c<EFBFBD> formu doldurup g<>nder tu<74>una bast<73><74><EFBFBD>nda,
|
||
<filename>action.php</filename> sayfas<61> <20>a<EFBFBD>r<EFBFBD>l<EFBFBD>r. Bu dosyaya a<>a<EFBFBD><61>dakileri
|
||
yazabiliriz:
|
||
</para>
|
||
<para>
|
||
<example>
|
||
<title>Formdan veri yazd<7A>rmak</title>
|
||
<programlisting role="php">
|
||
<![CDATA[
|
||
Merhaba <?php echo $_POST['isim']; ?>.
|
||
Siz <?php echo $_POST['yas']; ?> ya<79><61>ndas<61>n<EFBFBD>z.
|
||
]]>
|
||
</programlisting>
|
||
<para>
|
||
Bu betikten elde edilecek <20>rnek <20><>kt<6B>:
|
||
</para>
|
||
<screen role="html">
|
||
<![CDATA[
|
||
Merhaba Ahmet. Siz 22 ya<79><61>ndas<61>n<EFBFBD>z.
|
||
]]>
|
||
</screen>
|
||
</example>
|
||
</para>
|
||
<para>
|
||
Yap<61>lan i<> olduk<75>a a<><61>k. <varname>$_POST['isim']</varname> de<64>i<EFBFBD>keni
|
||
ve <varname>$_POST['yas']</varname> de<64>i<EFBFBD>keni PHP taraf<61>ndan otomatik
|
||
olarak yarat<61>ld<6C>. Daha <20>nce <varname>$_SERVER</varname> autoglobal
|
||
de<64>i<EFBFBD>kenini kullanm<6E><6D>t<EFBFBD>k, yukar<61>da <link linkend="reserved.variables.post">$_POST</link>
|
||
autoglobal de<64>i<EFBFBD>kenini tan<61>m<EFBFBD><6D> olduk. Bu de<64>i<EFBFBD>ken POST y<>ntemi ile g<>nderilen t<>m
|
||
veriyi i<>ermektedir. Formumuz i<>in tan<61>ml<6D> <emphasis>y<EFBFBD>ntem (method)</emphasis>in
|
||
POST oldu<64>una dikkat edin. <emphasis>GET</emphasis> y<>ntemini kullanm<6E><6D> olsayd<79>k,
|
||
form bilgilerimiz <link linkend="reserved.variables.get">$_GET</link> autoglobal
|
||
de<64>i<EFBFBD>kenine tan<61>mlanm<6E><6D> olacakt<6B>. Bunlar<61>n haricinde, istemciden gelen verinin hangi kaynaktan
|
||
geldi<64>i sizin i<>in <20>nemli de<64>ilse <link linkend="reserved.variables.request">$_REQUEST</link>
|
||
autoglobal de<64>i<EFBFBD>kenini de kullanabilirsiniz. Bu de<64>i<EFBFBD>ken GET, POST ve COOKIE verilerinin
|
||
birle<6C>iminden olu<6C>ur. Daha fazla bilgi i<>in <function>import_request_variables</function>
|
||
fonksiyonunu inceleyebilirsiniz.
|
||
</para>
|
||
<para>
|
||
PHP i<>inde XForms <20><>elerini de kullanabilirsiniz, ancak ba<62>lang<6E><67> a<>amas<61>nda
|
||
<20>ok iyi desteklenen HTML formlar<61> sizin i<>inizi g<>recektir. XForms ile <20>al<61><6C>mak yeni ba<62>layanlar
|
||
i<>in uygun olmasa da, ilginizi <20>ekebilir. <link linkend="features.xforms">XForms ile elde edilen
|
||
verilerin i<>lenmesi</link> ile ilgili metinden bu konu ile ilgili daha fazla bilgiye ula<6C>abilirsiniz.
|
||
</para>
|
||
</sect1>
|
||
|
||
<sect1 id="tutorial.oldcode">
|
||
<title>PHP'nin yeni s<>r<EFBFBD>mleri ile eski kod yap<61>s<EFBFBD>n<EFBFBD> kullanmak</title>
|
||
<para>
|
||
PHP' pop<6F>ler bir betik dili olmas<61>yla birlikte, haz<61>r kullanabilece<63>iniz
|
||
kodlar <20>reten bir<69>ok kamuya a<><61>k depo ve k<>t<EFBFBD>phane olu<6C>turuldu. PHP geli<6C>tiricileri
|
||
geriye d<>n<EFBFBD>k uyumlulu<6C>u m<>mk<6D>n oldu<64>unca korumaya <20>al<61><6C>t<EFBFBD>lar, dolay<61>s<EFBFBD>yla
|
||
eski bir PHP s<>r<EFBFBD>m<EFBFBD> ile birlikte yaz<61>lm<6C><6D> bir PHP kodu hi<68>bir de<64>i<EFBFBD>iklik yap<61>lmas<61>na
|
||
gerek duyulmadan (ideal olarak) yeni PHP s<>r<EFBFBD>mleri ile <20>al<61><6C>abilir halde kald<6C>.
|
||
Ancak pratikte, baz<61> de<64>i<EFBFBD>ikliklerin yap<61>lmas<61> gerekebilir.
|
||
usually be needed.
|
||
</para>
|
||
<para>
|
||
Eski kodlar<61> etkileyen yak<61>n ge<67>mi<6D>e ait iki <20>nemli de<64>i<EFBFBD>iklik a<>a<EFBFBD><61>daki gibidir:
|
||
<itemizedlist>
|
||
<listitem>
|
||
<simpara>
|
||
Eski <varname>$HTTP_*_VARS</varname> tipi de<64>i<EFBFBD>kenler <20>m<EFBFBD>rlerini
|
||
doldurdular (bu de<64>i<EFBFBD>kenler bir fonksiyon ya da metod i<>ersinde kullan<61>lmadan
|
||
<20>nce tan<61>mlanmal<61>yd<79>lar). Takip eden
|
||
<link linkend="language.variables.superglobals">autoglobal dizileri</link>
|
||
PHP'nin <ulink url="&url.php.release4.1.0;">4.1.0</ulink> s<>r<EFBFBD>m<EFBFBD> ile
|
||
birlikte kullan<61>ma a<><61>lm<6C><6D>t<EFBFBD>r.
|
||
Bunlar: <varname>$_GET</varname>, <varname>$_POST</varname>,
|
||
<varname>$_COOKIE</varname>, <varname>$_SERVER</varname>,
|
||
<varname>$_FILES</varname>, <varname>$_ENV</varname>,
|
||
<varname>$_REQUEST</varname> ve <varname>$_SESSION</varname>
|
||
dizileridir. Daha eski, <varname>$HTTP_POST_VARS</varname> gibi
|
||
<varname>$HTTP_*_VARS</varname> dizileri, PHP 3'teki ayn<79> kullan<61>m
|
||
bi<62>imi ile mevcutturlar.
|
||
&avail.register-long-arrays;
|
||
</simpara>
|
||
</listitem>
|
||
<listitem>
|
||
<simpara>
|
||
D<><44> de<64>i<EFBFBD>kenler art<72>k global kapsamda <20>ntan<61>ml<6D> olarak yarat<61>lmamaktad<61>rlar.
|
||
Ba<42>ka bir deyi<79>le, PHP
|
||
<ulink url="&url.php.release4.2.0;">4.2.0</ulink> s<>r<EFBFBD>m<EFBFBD> ile birlikte &php.ini;
|
||
i<>ersindeki bir PHP direktifi olan
|
||
<link linkend="ini.register-globals">register_globals</link>, <20>ntan<61>ml<6D> olarak
|
||
<emphasis>off (kapal<61>)</emphasis>hale getirildi. Bu de<64>erlere eri<72>im i<>in
|
||
tercih edilen autoglobal dizi kullan<61>m<EFBFBD> y<>nteminden yukar<61>da bahsettik. Eski
|
||
betikler, kitaplar ve e<>itmenler bu direktifin a<><61>k oldu<64>u kabul edilerek yaz<61>lm<6C><6D> olabilir.
|
||
Bu direktif a<><61>k oldu<64>unda, <20>rne<6E>in <literal>http://www.example.com/foo.php?id=42</literal>
|
||
URL'sinden gelen bir istek ile otomatik olarak <varname>$id</varname>
|
||
de<64>i<EFBFBD>keni olu<6C>turulur. Bu direktifin a<><61>k ya da kapal<61> oldu<64>una bak<61>lmazs<7A>z<EFBFBD>n,
|
||
<varname>$_GET['id']</varname> de<64>i<EFBFBD>keni yarat<61>l<EFBFBD>r.
|
||
</simpara>
|
||
</listitem>
|
||
</itemizedlist>
|
||
Bu de<64>i<EFBFBD>iklikler ile ilgili daha fazla bilgi i<>in,
|
||
<link linkend="language.variables.predefined"><EFBFBD>ntan<EFBFBD>ml<EFBFBD> de<64>i<EFBFBD>kenler</link> b<>l<EFBFBD>m<EFBFBD>nden
|
||
ve buradaki di<64>er ba<62>lant<6E>lardan faydalanabilirsiniz.
|
||
</para>
|
||
</sect1>
|
||
|
||
<sect1 id="tutorial.whatsnext">
|
||
<title>Sonraki ad<61>m nedir?</title>
|
||
<para>
|
||
Sahip oldu<64>unuz yeni bilgilerle k<>lavuzun bir<69>ok b<>l<EFBFBD>m<EFBFBD>n<EFBFBD> anlayabilir
|
||
ve <20>rnek ar<61>ivinde bulunan bir<69>ok beti<74>i okuyabilir hale gelmi<6D> olmal<61>s<EFBFBD>n<EFBFBD>z.
|
||
<ulink url="&url.php.links;">&url.php.links;</ulink> ba<62>lant<6E>s<EFBFBD>ndan
|
||
inceleyebilece<63>iniz ba<62>ka <20>rneklere ula<6C>abilirsiniz.
|
||
</para>
|
||
<para>
|
||
PHP ile neler yapabilece<63>iniz ile ilgili ba<62>ka sunumlara ula<6C>mak isterseniz,
|
||
<ulink url="&url.php.conf;">&url.php.conf;</ulink> ve
|
||
<ulink url="&url.php.talks;">&url.php.talks;</ulink>
|
||
adreslerindeki PHP Konferans Materyalleri Siteleri'ni ziyaret edebilirsiniz.
|
||
</para>
|
||
</sect1>
|
||
</chapter>
|
||
|
||
<!-- Keep this comment at the end of the file
|
||
Local variables:
|
||
mode: sgml
|
||
sgml-omittag:t
|
||
sgml-shorttag:t
|
||
sgml-minimize-attributes:nil
|
||
sgml-always-quote-attributes:t
|
||
sgml-indent-step:1
|
||
sgml-indent-data:t
|
||
indent-tabs-mode:nil
|
||
sgml-parent-document:nil
|
||
sgml-default-dtd-file:"../../manual.ced"
|
||
sgml-exposed-tags:nil
|
||
sgml-local-catalogs:nil
|
||
sgml-local-ecat-files:nil
|
||
End:
|
||
vim600: syn=xml fen fdm=syntax fdl=2 si
|
||
vim: et tw=78 syn=sgml
|
||
vi: ts=1 sw=1
|
||
-->
|
||
|