Selaa lähdekoodia

master adds sample data to frontpage

master
apoc 2 kuukautta sitten
vanhempi
commit
e00019e0d9

+ 17
- 1
docs/Series/4. http, servers/4.4 Common gateway interface.md Näytä tiedosto

@@ -24,4 +24,20 @@ int main()
}
```

then point your XAMPP apache to the compiled binary/runtime so once you load http://localhost in a browser you will see a page saying "Hello world!". Now you get how web development basically works: write a program/script, then point a web server to get said program's output.
then point your XAMPP apache to the compiled binary/runtime so once you load http://localhost in a browser you will see a page saying "Hello world!". Now you get how web development basically works: write a program/script, then point a web server to get said program's output.

--

## CGI script setup

To elaborate more on the "then point your XAMPP apache to XYZ" part, if you get variability and how programs/functions work in general (see documents 1.4, 1.5), you will understand that what happens at server run-time is that the

```
/var/www/html/
```
or
```
C:\xampp\htdocs
```

directory (whichever one you are operating on (depending on the OS)) is basically a parameter, instructing the server program to ask the filesystem for data stored in that directory. In our previous case it was an index.html file within /var/www/html (or the other one), for the rest of this project and as we are dealing with PHP, the data that we are initially giving the web server will be an index.php script/file - instructing the server to pass the script/file contents to a PHP-interpreting program (usually php-fpm (on older setups php-cgi)).

+ 28
- 0
docs/Series/4. http, servers/4.5 Running the code.md Näytä tiedosto

@@ -0,0 +1,28 @@
Based on information from documents

- 4.4 Common gateway interface
- 2.1 (Git) situational awareness

and with a XAMPP setup from

- 4.1, 4.2, 4.3, 4.4

you should be able to clone (and pull for any subsequent update) the repository locally then point your browser to the web documents (HTML) or CGI scripts (PHP) on http://localhost. If you run into a hiccup feel free to e-mail me to ask for solutions: apocpublic@outlook.com

--

What to expect then? Well if you had cloned the repository to /var/www/html or wherever the server loads resources from you would have been greeted with our index.htm file (index.html, same thing, if the .htm version doesn't work rename the file to index.html) showing you the page. Now how do we load our sample CSV file with the script in the ./src/ subdirectory?

In case you haven't noticed, I've renamed index.htm -> index.php and written in a <?php ?> enclosed piece of script into the existing HTML,

```
<?php require './src/index.php'; ?>
```

What this did is it instructed the server reading the contents (see document 4.2 point #6) of the index.php file that "require './src/index.php';" is something it should pass along to the PHP interpreter, and the interpreter has then in turn read that instruction with "./src/index.php" as a parameter, combining the /var/www/html path with ./src/index.php getting "/var/www/html/src/index.php" as the path of a script _required_ for our script to function, ensuring it getting loaded every time. The end result is the ./src/index.php code executed from ./index.php, the

```
file_get_contents
```

instruction finally loading the sample CSV contents into the frontpage.

index.htm → index.php Näytä tiedosto

@@ -22,6 +22,7 @@

<!-- home page html below this line-->
<div class='box'>
<?php require './src/index.php'; ?>
<h2>catalog</h2>
<section class='content'>


Loading…
Peruuta
Tallenna