How can I get php to respond to get request? - php

As a preface I would like to say that I am very new to php AND to stack overflow so this is a very beginner question.
For some context: I am doing an ubuntu autoinstall and am following the following forum post for some extra settings I'm trying to do: https://askubuntu.com/questions/1290624/fetch-autoinstall-based-on-mac
So the installer does a curl command which if understand correctly sends a GET request to the http server which will run some php code and finally return an edited file (is what is supposed to happen). How can i get a php environment up and running to do just this?
I have the apache http server running which I can use to get files with curl, I just need to know how to "catch" the get request and send back an edited file.

just create a PHP file in your webserver root directory then send your request to http://yourserver/your_php_file.php
Your webserver will call the file your_php_file.php and this file will have to send back an edited file ;)

Try with a simple index.php file and navigate to it via the URL. The index.php file can be just this for starter:
<?php
var_dump($_GET);
and after you see what is $_GET (and I recommend read about it) you will figure out what to do next :)

Related

Slashes after .php

I'm trying to analyse the packets sent by an application through WireShark and I came across this line:
POST /main.php/login/authkey HTTP/1.1
Question:
1. Is main.php a directory or a php file?
2. Is authkey a php file? Related to .htaccess?
Sorry if this question was asked before, but I don't know how to describe this to search with.
EDIT:
The response given is: HTTP/1.1 200 OK
Server is apache
It is impossible to authoritatively tell what the server does with any given URL, but the most likely answers are:
A PHP file
It is something which is interpreted by the code in main.php (via $_SERVER['PATH_INFO']).
What you see is the request. As the server can parse at anyway it wants (e.g.: redirect all requests to /index.asp) there is no answer to be given.
We can however guess a bit. Possibilies are that main.php is a script, that uses the '/login/authkey' url-part to start expecting a post for the functionality login (using an authkey perhaps?)
It can be that a .htaccess file either redirects the request to a file called main.php (seems likely from the name), or that it first redirects to some sort of index, that finds the part about main.php.
Technically, main.php can be a directory, too. From the request line alone, it can not be said at all. Same applies to authkey, it could be a PHP file as well. However only from request URI path alone, you actually can not say nothing but just speculate. Instead, you need to look into the server configuration and then look-up the files / directories on the server itself.
To make this more prominent: The response could be a 404. You're not providing any response information.
Apart from that, it's a common feature of the Apache webserver that requests with URI paths that contain a PHP file will get passed along to that PHP file.

Code shown as text output

I'm a newbie to Facebook app development. It almost works when the page liked.php is shown (it's shown when a user liked the site), the PHP code is displayed as text output.
my liked.php code:
deleted for privacy reasons
?>
Here's the output(it's shown as blank text):
I simply don't know why. Even the error_reporting(E_ALL); doesn't show anything. Simply blank text output. I use the newest facebook php sdk.
I guess the problem is not in the code but in the configuration of your server. You need to tell the server to execute the php code instead of displaying it.
Sounds like you either don't have PHP installed or you're not using a file extension which invokes the PHP engine - is your file called [Blah].php?
Some things to check:
You're serving the file from a web server (not locally)
The server has PHP installed
Your webserver is configured to use the PHP engine to handle the file type you're using (usually .php or .php4 or similar)
creating a new file with just <?php phpinfo(); ?> and serving it should give you lots of info about your PHP install.
If you have access to the server, you should be able to run PHP from the command line/shell

I have a problem with my php script

I have a form where it request name,email,zipcode. However the problem is that. when you click on submit. it ask you to open the file it doesn't go to the script.
The website is http://childcarelv.org/newsletter.html
PHP isn't being handled by your server. Instead, it is just being output straight to the browser.
This is a server configuration issue.
Your server is configured with the correct MIME type (it is returning application/x-httpd-php), but isn't set up to actually use PHP to process it.
Since you are using Apache, read the configuration instructions here: http://www.php.net/manual/en/install.unix.apache2.php
Looks like you might be hosting with ipower.com. If that is the case, this is an issue for them to solve.
From your description it seems that server is not able to execute the php script, and thus gives it as download to the client.
You should try to put the following code in a file named testphp.php and place in your public home directory and go to the page to see if php extension is mapped to the php module on your server.
<?
phpinfo();
?>
This is just to verify/prove that there is nothing wrong in your script, and even a simple test script won't work.

.htaccess permissions to stop outside world executing php scripts

I am setting up a new website and currently if I go to mydomian/php/someScript.php it will execute the php script. How can I let the files that include this still include this but not let anyone else execute these scripts from the browser. Currently I have this in my .htaccess file:
deny from all
but when I visit the site a AJAX post request is made to a script in this folder and is getting back a 403 error.
Any ideas on how to achieve this are welcome.
====EDIT====
for clarity, some files in the php directory are requested by AJAX and I've now been made aware that these files cant have the desired permissions. However I would still like to put these permissions on the other files in this directory
Thanks
The best solution is to put them outside of the web root directory if at all possible, that way you can include them but the web server can't serve them, no configuration is required at all in this case.
EDIT: I noticed you want to allow access to the scripts by AJAX. There is no way of doing this as there's no way of telling the difference between an AJAX request or other types of HTTP request with any reliability.
You can still include those files from php, e.g. using include or require.
Calling it via AJAX is not different from calling it by entering the URL in the browser - i.e. you cannot block direct access but allow AJAX access.

PHP app in liferay - HTTP Status 404

I'm a liferay newbie. I'm trying to write a simple php app that echos some text and add it as a plug in to liferay. I've created the file helloworld.php, zipped it up and installed it. Finally I add it to the page but am getting the following error:
HTTP Status 404 - /helloworldapp/
type Status report
message /helloworldapp/
description The requested resource (/helloworldapp/) is not available.
Apache Tomcat/6.0.26
Can anyone help me?
Jonesy
text editor had slying appended a .txt onto the end of index.php
I only saw it when I displayed the directory in the CLI. removed the extension and it works..
You are using Apache Tomcat Server right? And the code is a PHP script? I am more confused as what do you actually want to achieve?

Categories