|
użytkowników online: 68
|
OPINIE UŻYTKOWNIKÓW
|
Mimo, że strony WWW tworzymy już 5 lat zawsze znajdziemy coś ciekawego. Świadczy o tym chociażby nasza aktówka, w której znajduje się kilkadziesiąt porad, z których często korzystamy. Otwarta forma poradnika, czyli możliwość podrzucania tematów oraz wspólny ich rozwój, to nieoceniona pomoc. Uważam, ze abonament roczny jest niewspółmiernie niski do jakości zaprezentowanych materiałów.
Marek Kończal
Internetix.pl
|
|
PODRĘCZNIK PHP 5.x, 4.x, 3.x - częściowo spolszczony / źródło: www.php.net
[Spis]
[A]
[B]
[C]
[D]
[E]
[F]
[G]
[H]
[I]
[J]
[K]
[L]
[M]
[N]
[O]
[P]
[Q]
[R]
[S]
[T]
[U]
[V]
[X]
[W]
[Z]
Utwórz w głównym katalogu serwera (DOCUMENT_ROOT) plik o nazwie
hello.php i następującej treści:
Przykład 2-1. Twój pierwszy skrypt PHP: hello.php |
<html>
<head>
<title>Test PHP</title>
</head>
<body>
<?php echo "<p>Witaj Świecie !</p>"; ?>
</body>
</html>
|
Teraz korzystając z przeglądarki internetowej otwórz wcześniej utworzony plik,
podając jego pełny adres URL (np. http://twoj.serwer.pl/hello.php).
Jeżeli testujesz swój skrypt lokalnie, jego adres URL to, zależnie od konfiguracji serwera,
http://localhost/hello.php lub http://127.0.0.1/hello.php.
Zwróć uwagę na dyrektywy DocumentRoot i
ServerName w pliku konfiguracyjnym twojego serwera
(dla serwera Apache jest to plik httpd.conf). Jeśli wszystko jest poprawnie
skonfigurowane, interpreter PHP przetworzy plik i wyśle do przeglądarki następujące dane:
<html>
<head>
<title>Test PHP</title>
</head>
<body>
<p>Witaj Świecie !</p>
</body>
</html> |
|
Zauważ jak bardzo to się różni od skryptów CGI. Plik nie musi być kompilowany
ani poddawany jakimkolwiek innym przetworzeniom.
To chyba najprostszy program, jaki można sobie wyobrazić i chyba naprawdę
nigdy nie będziesz musiał używać PHP do tworzenia stron takich jak ta.
Całe jego zadanie polega na wyświetleniu zdania: Witaj Świecie !
przy użyciu wbudowanej w PHP instrukcji echo().
Jeżeli po wypróbowaniu tego przykładu w przeglądarce pojawiła się pusta strona,
otworzyło się okno z pytaniem o zapisanie pliku lub też wyświetliła
się cała zawartość hello.php, bardzo możliwe, że serwer ma
wyłączoną obsługę PHP (lub też nie ma jej wcale). W takim wypadku poproś
administratora o jej aktywowanie przy pomocy wskazówek z rozdziału
Instalacja. Jeśli tworzysz skrypty lokalnie,
również powinieneś zapoznać się z treścią tego rozdziału, aby
upewnić się czy wszystko jest poprawnie skonfigurowane. Gdy problem mimo wszystko
w dalszym ciągu się powtarza, skorzystaj z informacji zawartych na stronie
Pomocy technicznej PHP.
Głównym celem tego przykładu było pokazanie specyficznej składni PHP.
Najpierw użyliśmy znacznika <?php, aby poinformować
interpreter, że w tym miejscu rozpoczyna się kod PHP. Następnie wprowadziliśmy
instrukcję wyświetlającą napis Witaj Świecie ! i zakończyliśmy
skrypt znacznikiem ?>. W ten właśnie sposób możesz
mieszać kod PHP ze znacznikami HTML. Więcej informacji o składni PHP
znajdziesz w rozdziale Podstawowa składnia.
Edytory tekstowe:
Istnieje wiele tekstowych edytorów i zintegrowanych środowisk programistycznych (IDE),
których możesz użyć do tworzenia, modyfikowania i zarządzania skryptami PHP.
Obszerna lista takich programów znajduje się na stronie
http://www.thelinuxconsultancy.co.uk/phpeditors.php.
Jeżeli chciałbyś polecić innym jakiś edytor, zajrzyj na powyższą
stronę i poproś jej właściciela o dodanie programu do spisu.
Procesory tekstu:
Programy takie jak StarOffice Writer, Microsoft Word i Abiword nie nadają
się zbytnio do pracy ze skryptami PHP. Jeżeli mimo to chcesz korzystać z którejś
z wymienionych aplikacji, musisz mieć pewność, że kod skrypu zapisywany jest jako zwykły tekst.
W przeciwnym wypadku PHP nie będzie w stanie przetworzyć pliku.
Notatnik Windows:
Jeśli piszesz skrypty w Windowsowym Notatniku, sprawdzaj czy pliki zapisywane
są z rozszerzeniem .php (Notatnik domyślnie zapisuje wszystkie pliki dodając rozszerzenie .txt).
Kiedy zapisujesz plik i program wyświetla okno dialogowe z pytaniem o nazwę pliku,
umieść tę nazwę w cudzysłowie (np. "hello.php"). Drugim sposobem
jest wybranie z rozwijanej listy 'Zapisz jako typ' w tym samym oknie opcji
'Wszystkie pliki' (zamiast ustawionej domyślnie 'Dokumenty tekstowe (*.txt)').
Teraz możesz podać nazwę pliku bez cudzysłowów.
Teraz kiedy napisałeś już pierwszy działający program, czas stworzyć chyba
najbardziej znany skrypt PHP! Stwórz nowy plik, umieść w nim znaczniki PHP
i wywołaj funkcję phpinfo(). Po uruchomienia skryptu, ujrzysz w
swojej przeglądarce długą stronę zawierającą wiele przydatnych informacji o twoim
systemie operacyjnym i ustawieniach takich jak
zmienne predefiniowane,
załadowane moduły PHP, i opcje konfiguracji.
Poświęć trochę czasu na przejrzenie tych informacji.
User Contributed Notesnycrdeary
06-Jan-2006 01:04
nobody
18-Oct-2005 10:50
ttw at cobbled dot net
26-Jul-2005 12:00
it's worth adding some basic HTML before and after your test scripts as it helps pickup syntax errors. for example
<html>
<head><title>test page</tile></head>
<body>
<?php echo "hello world"; ?>
</body>
</html>
will give a blank page (note the error in closing "title" tag). think this is in the FAQ as white screen of death hopefully useful here too.
onebadscrivener at gmail dot com
18-Jan-2005 02:25
OS X users editing in TextEdit will need to make sure their TextEdit preferences are set to allow plain text files. Under the TextEdit pull-down menu, choose PREFERENCES, then under NEW DOCUMENT ATTRIBUTES in the window that pops up, click PLAIN TEXT.
Then, in the section of that same window called "saving," DESELECT "append .txt extension to plain text files." This will allow you to save your files with a .php extension.
Then close the PREFERENCES window. You're good to go.
jo at durchholz dot org
30-Sep-2004 02:53
If PHP is running under Apache, there are very different ways to tell Apache what's a PHP script and whether it should be executed. If you can, locate the httpd.conf and look for the appropriate settings; if you can't, ask your site administrator.
The options are:
1) Make Apache interpret any PHP files it finds and serve them like HTML. This kind of set-up is rare, as it is extremely unsafe. PHP "safe mode" is intended to give some measure of protection in such situations, but it doesn't even approach that of setup (3b), below (safe mode is over-restrictive in some areas and not restrictive enough in others, and too many PHP scripts will break in safe mode anyway, so I decided against it - YMMV).
2) Make Apache interpret PHP files only if they are found in some specific URL area (usually /cgi-bin/whatever). This doesn't help in protecting different users from each other, but it makes it more obvious if, say, a file upload would overwrite a script. (It's not a real protective measure though. File uploads shouldn't be permitted except into specially designated data directories with a .htaccess file that disallows script execution of any kind. Actually this applies to any kind of file creation, e.g. many Wikis allow the user to type in a topic name and will create a text file with that name - so the directory in which the name is created should be made non-executable.)
3) Make Apache hand over .php, .sh, .pl etc. etc. to the Unix shell for interpretation. This has the advantage that Apache can use the "suEXEC" mechanism, which allows it to impersonate some other user than the standard "nobody" or "www-data". For example, if multiple users are allowed to create PHP scripts on the same server, the server administrator will create a separate user account for each, and have Apache impersonate the appropriate account. Unfortunately, this setup gives up a large amount of efficiency, which means that the hoster has to set up a larger machine for the same load. In other words, hosting accounts will be a bit more expensive but *far* more safe.
3a) A badly-configured setup of this kind will require that you insert a line like "#! /usr/bin/php4" at the top of each PHP file. Of course, this is simply too much work for even modest amounts of PHP on a site, but some (few) sites require this anyway.
3b) A better-configured setup will recognize file types from the file extension (just as Windows does it). If you have a (3a)-style setup and know or suspect your provider has a Linux box running, talk to him about the binfmt_misc extension. It requires about a hour to install properly and (possibly) a kernel recompilation (that's another hour or two if they are just running preinstalled boxes, and a near-zero overhead if they're installing their machines anyway).
Most sites combine setup (2) with safe mode. In that case, do a regular backup of everything that you have on the server, since your site is open to attacks from script kiddies that live on the same machine. (Source Forge had incidents of that kind.)
(Note that this kind of problem applies to Perl scripts, or any kind of scripting that can create or overwrite files. For example, the TWiki site on SourceForge got clobbered by this at least once - well, SourceForge is particularly vulnerable to this because anybody with a browser and pretending to do open source development will be allowed to upload CGI scripts.)
Curtis
10-Aug-2004 11:47
Expansion on saving w/ notepad/wordpad: (tested on XP; but should work on 2000,NT, and 98)
You can associate the .php file extension w/ Windows w/o going into the registry.
Open up My Computer or MSIE in file mode. Go to folder options > File types tab. Now click new. Add the extension as PHP or php. If you can't find the PHP application in the dropdown list under advanced, just go OK, for now. At least the extension is in place.
Now, try and create a php file by using the directions from this page of the PHP tutorial (should save it with the rest of your HTML files, i.e. your DocumentRoot). If you go to view your php file listed in the directory, and you see that it's still a .txt file, right-click the icon to see if you can locate "open with." If so, you should be able to browse for the appropriate file, which should be at (may vary, depending on where you installed PHP):
C:\PHP\php.exe
Click that as the default program, and the PHP logo should appear on all your scripts, and no problems saving should occur w/ any program.
Good luck.
john at php dot com
02-Jan-2004 04:45
att. to adobe golive users,
golive is not widely seen as a comfortable php source code editor, as its use you might find it difficult but theres never a "no";
to work with php you must first realize the dynamic wizard (and its still more important if youre building a website)
full-house with adobe golive cs, which is the newest one and it has improved in some aspects which newbies cannot see,
Slowpoke
10-Sep-2003 09:27
Mac Users
For those using MAC OSX, you've already got an Apache Server, you just need to switch it on.
Go to: preferences>sharing and turn 'personal web-sharing' on. Then open up you browser and go to http://localhost/ and you should get a screen telling you all about your server. Well done, your Apache Server is switched on and working.
There's a little more to it that that though. You may need to set up PHP and mySQL. I've taken the liberty of throwing you a very useful link that should get your server up and runninig with everything you need, as well as giving you a brief insight into how useful PHP and mySQL can be. It's a big'un!
http://www.macdevcenter.com
/pub/a/mac/2003/04/04/
apache_jaguar_pt1.html
(I had to break this to get it posted I'm afraid)
Thats all for now,
chow chow
Slowpoke
ryan420 at earthling dot net
03-Feb-2003 11:18
Note on permissions of php files: You don't have to use 'chmod 0755' under UNIX or Linux; the permissions need not be set to executable. Again, this is more like a html file than a cgi script. The only mandatory requirement is that the web server process has read access to the php file(s). With many Linux systems, it is popular for Apache to run under the 'apache' account. Given that HTML and other web files, like php, are often owned by user 'root' and group 'web' (or another similar group name), acceptable permissions might be those achieved with 'chmod 664' or 'chmod 644'. The web server process, running under the 'apache' account, will inherit read only permissions. The 'apache' account is not root and is not a member of the 'web' group, so the "other" portion of the permissions (the last "4") applies.
|