Understanding PHP URL [closed] - php

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Very fundamental question
I have phplist project set-up in net beans. URL I am accessing is
http://example.com/admin/ and
all the files are under list folder.
In debugging I can see that all the times execution starts from index.php file in lists folder.
What I am not getting is how does the particular php file associated with URL gets executed.
Meaning
http://example.com/admin/
should execute admin.php, but how does the execution goes to admin.php

if you enter only the file path like you did, it runs the index.php file, if you want to run any file in the folder, append the filename to the path like this: http://example.com/admin/admin.php

Typically with applications like this, all of the page accesses are routed through the index.php script, which examines the URL and maps/routes the request to the correct script based on what it contains.
A quick peek at the source of phplist makes it seem like that is indeed what is going on - look at the index.php for more detail.

Related

How to run a PHP script every time someone visits your site? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I need to run a PHP script every time someone visits a URL on my web page. how can I do this with apache2.4 and PHP-FPM? I also needed to preserve all the data (like the headers) from Apache. I am trying to use PHP and on every url even the errors.
What you can do is to have php.ini autoprepend a script to each of your pages.
This should be a starting point for you:
# Prepend file to top of page
auto_prepend_file = '/yourpath/pre_header.php'
Note that php.ini is server related so this will affect all sites you host unless you do something like what is described here to have a php.ini for each site.
Regarding the content of the script and what to do with the information you are free to do whatever you want with that script. The pro is that you don't have to modify any file and this will be executed for any php page your server is serving
You can just include the file containing the code (file.php) you want to execute in top of your php code like this and it will execute everytime someone visits your original php file:
<?php
include 'file.php';
// rest of your code goes below
If you want to preserve the header information too. Capture that in some variable and array and pass that to your file.php.
For passing the header information, you might need a function for that in your file.php file.
You can send those information as parameters via calling your function. Better to use classes.

PHP htaccess URL rewriting [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am currently writing an app where you can add a comment to a post based on IdTicket.
<td>Comments</td>
I am passing the Id value in my URL which is a part of the table. It is a dynamic value, different for every ticket. I am using $_GET['IdTicket'] on the comment.php page to get the id and based on that write a comment.
Is there a way to rewrite that link in htaccess? It would be perfect to hide everything or just make it prettier. And how would it look applied to that table?
Sure that is possible. And there are already countless examples for this...
You need to change the reference you hand out in your spplication logic:
Comments
And you need to take care to internally rewrite the incoming request to the actual resource again:
RewriteEngine on
RewriteRule ^/?comments/(\d+)$ /comments.php?IdTicket=$1 [QSA,END]
Obviously the rewriting module needs to be loaded. And if you want to use distributed configuration files (instead of the real host configuration inside the http server) you also need to have enabled the interpretation of those for host and location.

How do you move a website from localhost to server without changing much? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
For example in my website I have so many links say
"http//localhost/website/admin.php"
Which I want to be
"http://website.com/admin.php"
For now, I just use replace command in editor but it takes long time to figure out. But i was thinking $_SERVER['DOCUMENT_ROOT'] could solve this problem. But it did not either.
So how do you move your files from loalhost to server without changing anything? And I am not talking about wordpress site here. Its the one I created myself.
To start with you could make a defines.php file and include it in your index.php. What you could add is this: define('BASE_PATH', dirname(__FILE__));
This means when you enter for example this: $this->basePath = BASE_PATH . '/lib/company/Layouts/'; you will always have the right base_path incase you switch servers.
I suggest to use PHPStorm: www.jetbrains.com/phpstorm. Read the documentations to learn about the possiblities. You can for example press CTRL + R and search for 'localhost'. Now you receive a display so you can edit ALL localhost with another input. But there are many more functions. PHPStorm is a must-to-have.
Somehow you still need to edit your files only once and the defines.php could be the solution for your next projects or in future current project.
I hope this helped you.

Php opens as Text when usign "send" [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
So, i've be reading a lot of post here, but as my english is not that good, i cant understand all of it.
Sorry if this has been asked here before AND ANSWERED.
My problem is that, when i launch my html file wich contains a form it opens fine... but when i click the "send" buton, it opens the post.php file as a text and doesnt launch it.
I've managed since reading your posts, that it could be a link problem and it was. If i open it from the html file, the php opens at "file:///C:/wamp64/www/Pagina/Insertar.php" (and it fails) but if i type "Localhost/Pagina/Insertar.php" it opens just fine and upload the //empty// data to my database.
What can i do to make the "send" button work? i mean, make it goes to localhost instead of file://c.
Thank you in anticipate.
( and "insertar.php" is in the same folder)
PHP scripts are only executed when loaded through a server. It sounds like you're using a relative URL for the action attribute, and loading the HTML page from a local file instead of the server. So you need to change the action to point to the server.
<form action="http://localhost/Pagina/insertar.php">

Best way to hide back-end in PHP? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Im working on a PHP based web app which allows users to login. What would be the appropriate method of 404'ing all the back-end - (the actual application pages).
I've got a user-tools class which has a check-login function in it, that I use at the moment. If the user isn't logged-in, it redirects to a 404.
However I'm wondering is there a better way to set this up? Could I have a global page that has a list of all the pages that should 404 if the user isn't logged in? If so, how would you set that up?
Many website have all their traffic through a single entry point. In such a setup, you can define a constant in that single file, and check it in every file that is included, so you know whether the file was in fact loaded by the entry file. This method is implemented in MediaWiki for example.
Another solution is to put all the include files outside of the document root. Many frameworks (like CodeIgnitor and others) allow you to specify this directory, and allow you to put it anywhere you want. If it's outside the doc root, visitors cannot load files from that directory directly.

Categories