HTTP Get with variables - php

I have spent 2 days on this and are now stumped, having tried dozens of different methods and lots and lots of googling.
I need to retrieve data generated by a php page running on apache, using the GET command. This works fine when I am connecting with the LAN, but if I connect remotely then I am unable to get any response when there are variables in the path.
This works bot locally and remotely and I get the expected output from the php page.
GET /myfolder/mypage.php<CR><LF>
However, add a variable to the path and I get the correct response on the LAN but connecting remotely I get no response whatsoever:
GET /myfolder/mypage.php?var1=1&var2=2<CR><LF>
Just to reiterate, this works fine when accessing from the LAN and works fine in a web browser, but when I send as effectively a Telnet request I get nothing at all.
Any ideas ??
EDIT
The request is being sent to Linux Apache web server via a serial > tcpip gateway with a carriage return and linefeed at the end. The syntax works perfectly on the LAN with the ?var1= etc but as soon as I add ?var=1 when connecting externally nothing at all is returned, in fact apache logs don't show any record of the connection request.
I ## SUSPECT ## this may be something related to apache mod rewrite ?

May be can try something like below and specify the host and also the ver of HTTP being used.
GET /myfolder/mypage.php?var1=1&var2=2 HTTP/1.1
Host: 127.0.0.1

Related

Cannot Access Bud .serve URL (http://localhost:3000/) via Windows Host, Despite Reverse Proxy of Port 3000 Out of Devilbox PHP Container

I run the following command within my Roots Sage 10 theme directory, whilst inside a Devilbox Shell / Docker Container on Windows WSL.
yarn dev
My proxy url works fine. My server url says "localhost refused to connect".
I'm expecting my server url to deliver the same website, but auto update with development changes.
I've tried setting up a Reverse Proxy for Port 3000 as per the link below, but I still get the same error. https://devilbox.readthedocs.io/en/latest/reverse-proxy/reverse-proxy-with-https.html
I can see the funnel next to my vhost and when I check the config, I can see the following.
proxy_pass http://php:3000;
Not only does my server url still have the same error, my proxy url now says "502 Bad Gateway".
I wasn't sure if I should be leaving php as it is or changing that to say localhost.
According to the link below, it should stay as PHP "Node projcet hostname: php (will always be php)"
https://github.com/cytopia/devilbox/issues/240
This seems to contradict someone else's solution...
proxy_pass http://172.16.238.1:3000;
Taken from... https://gist.github.com/stkrzysiak/7892ab681ca826046bb8b66ccfd6c4ce
The comment to leave as php is most recent though, so I'm leaving it as that for now.
I've tried many combinations, including making changes to my bud.config.js file. Current settings...
.proxy('http://kwd-it.loc')
.serve('http://localhost:3000');
If anyone can offer any assistance, it would be greatly appreciated.

DNS lookups in php - how to use external name server

I'm running a simple php script that loops through a list of URLs and does a DNS lookup and saves the A record in a database. Runs perfectly on my local server but when I put it on my live server, the records are all internal 192... because its using the internal DNS server.
I'm using Net_DNS2 and have told it to use google DNS:
$r = new Net_DNS2_Resolver(array('nameservers' => array('8.8.8.8')));
but this doesnt seem to be working, I still get back 192 internal addresses.
Any ideas how to resolve this? I already moved to Net_DNS2 from the php dns_get_record function so that I could set a nameserver, but it doesnt seem to be working.

file_get_contents() not working properly

Any ideas why file_get_contents() is not working properly on server A but works on server B for certain websites?
$f = file_get_contents("https://developer-api.nest.com/devices.json?auth=c.GGU9iS...");
This echoes absolutely nothing on server A, but it works on server B, I've tested everything...
a) allow_url_fopen is ON
b) If I do file_get_contents(); getting another website, it works on both servers.
c) I've tried using cURL and still got nothing on server A but does get something on server B.
d) I've tested cURL with another website and it does work both servers.
e) Tried to do var_dump($http_response_header); and returns NULL on server A.
I don't know what's going on, I've done anything.
UPDATE:
I did wget https://developer-api.nest.com/devices.json?auth=c.GGU9iS... on server A and it never connects, and just noticed it's using port 9553, if I do this same wget on this other server (B) it works correctly. I'm so confused.
I echoed curl_error(); and it returns couldn't connect to host, but it's working perfectly on my other server. This is driving me crazy.
Fixed it.
I added the port to the iptables that the url is using, as it's not an "normal" port and restarted my firewall and worked perfectly.
Thank you.

Requesting file via PHP fails, but succeeds in Python

The URL in question : http://www.roblox.com/asset/?id=149996624
When accessed in a browser, it will correctly download a file (which is an XML document). I wanted to get the file in php, and simply display its contents on a page.
$contents = file_get_contents("http://www.roblox.com/asset/?id=149996624");
The above is what I've tried using (as far as I know, the page does not expect any headers). I get a 500 HTTP error. However, in Python, the following code works and I receive the file.
r = requests.get("http://www.roblox.com/asset/?id=147781188")
I'm confused as to what the distinction is between how these two requests are sent. I am almost 100% it is not a header problem. I've also tried the cURL library in PHP to no avail. Nothing I've tried in PHP seems to succeed with the URL (with any valid id parameter); but Python is able to bring success nonchalantly.
Any insight as to why this issue may be happening would be great.
EDIT : I have already tried copying Python's headers into my PHP request.
EDIT2 : It also appears that there are two requests happening upon navigating to the link.
Is this on a linux/mac host by chance? If so you could use ngrep to see the differences on the request themselves on the wire. Something like the following should work
ngrep -t '^(GET) ' 'src host 127.0.0.1 and tcp and dst port 80'
EDIT - The problem is that your server is responding with a 302 and the PHP library is not following it automatically. Cheers!

When I run following url on my browser it runs fine but when i use php function its getting 505 Page . Can any one help me with that

$output = file_get_contents("http://www.canadapost.ca/cpc2/addrm/hh/current/indexa/caONu-e.asp");
var_dump($output);
HTTP 505 Status means the webserver does not support the HTTP version used by the client (in this case, your PHP program).
What version of PHP are you running, and what HTTP/Web package(s) are you using in your PHP program?
[edit...]
Some servers deliberately block some browsers -- your code may "look like" a browser that the server is configured to ignore. I would particularly check the user agent string that your code is passing along to the server.
Check in your PHP installation (php.ini file) if the allow_url_fopen is enabled.
If not, any calls to file_get_contents will fail.
It works fine for me.
That site could be blocking the server that you're using to access it.
When you run the URL from your browser, your own ISP is used to get the information and display in your browser. But when you run from PHP, the ISP of your web host is used to get the information, then it passes it back to you.
Maybe you can do this to check and see what kind of headers its returning for you?
$headers=get_headers("http://www.canadapost.ca/cpc2/addrm/hh/current/indexa/caONu-e.asp");
print_r($headers);

Categories