D
D
Dmitry2015-10-16 16:40:27
PHP
Dmitry, 2015-10-16 16:40:27

How to accept http requests?

Through htaccess I send all requests to index.php
RewriteRule ^(.*)$ index.php [L,QSA]
Now in index I need to accept and process them somehow. How to take them?
The result should be a list of all sent requests, including pictures, styles, etc.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Stalker_RED, 2015-10-16
@Stalker_RED

I think it's not a secret for you that all requests for styles, pictures, etc. this is not one big request, but each resource is requested separately.
You can see the list of all requests in Apache's access.log, or whatever you have there. Static is usually given by means of a web server (nginx, apache) without pulling php for this.
The approach where all requests (or all requests to non-static files) are redirected to one php file is called " single entry point ", there are a lot of articles on the net describing how to do this.
In short:

#кусок из symfony
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^(.*)$ /app.php [QSA,L]

those. the request gets into app.php only when there is no static file.
For example: if the /images/logo.png file exists, it will be returned by the web server itself, if it does not exist, the request will go to php.
The entry point in php is organized something like this:
We take the value from $_SERVER['REQUEST_URI'], pass it to some thing, which is often called routing , which parses it and decides which piece of code to run next.

V
VisualIdeas, 2015-10-16
@VisualIdeas

Parse the global variable $_SERVER["REQUEST_URI"] and dance from it.
Get it out first

<?php
   echo $_SERVER["REQUEST_URI"];
?>

And then the regular expressions, or the banal explode(...);

I
IceJOKER, 2015-10-16
@IceJOKER

Images and all sorts of resources are better not to send to index.php
in index.php :
var_dump($_SERVER);

E
Everal, 2015-10-16
@Everal

look in $_GET $_POST then
you will understand

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question