file_get_contents() not working properly - php

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.

Related

ftp_rawlist always fails on FTPES server with passive mode

I have to connect to a FTPES server to retrieve data. Connecting and logging in works just fine, but my call with ftp_rawlist always fails and returns "false".
I am using this code for debugging purposes:
$ftp = ftp_ssl_connect($ftp_host);
if (ftp_login($ftp, $ftp_user, $ftp_pass)) {
$p = ftp_pasv($ftp, true);
var_dump($p);
$r = ftp_rawlist($ftp, '/', true);
var_dump($r);
} else {
echo 'Could not login';
}
$p is always true, $r always false.
When I connect to the server through Filezilla everything works fine and I can list directory content and more.
Update #1: Tried to not only list '/' but various subfolders on the server, they all fail through the script.
Update #2: Also tried to use ftp_raw with the commands to get a list, but the LIST command runs for some time and then does not return any result at all. But HELP lists LIST as a valid command for the server... Strange...
Update #3: I tried phpseclib now, but while I can connect, I can't login with the user/password combination. Support from the maintainer of the FTPES server is not happening ("works fine for $somebody else..."), so I need to figure this out another way... :-)
To come to an end with this: As the deadline for this project came closer a solution had to be found. And although this is no real answer in the sense of a question, I'd like to show what I have done to have this fixed. Maybe someone stumbles upon this through googling.
Next to the things mentioned in the OP, I also tried connecting to FTPS using PHP and certificate as auth which didn't work either. As nothing works as it is supposed to, I wonder if the FTPS server is really configured correctly after all.
The people who run the server told me that everything is fine and their CLI CURL-call works fine for them, so they have no need to further investigate issues.
As a result of this I set up a sandbox account on a server which has shell_exec() enabled. There is now a script running which gets a file listing via CURL and then downloads the files via CURL with the commands provided by the server provider. That server can be accessed through normal SFTP and therefore acts as a "Proxy FTP" which regularly mirrors the remote FTPS server file structure.
Although I find this "solution" quite "hacky" it seems to run robust, stable and fast for the moment. We will therefore be able to have the operation running this way in this year (it only runs around three months before christmas) and will have a look into it in the new year and develop a more stable solution.
Maybe the server guys are also less stressed then and willing to help... ;-)
Add the following call to ftp_set_option() in a line before the call to ftp_pasv
ftp_set_option($ftp, FTP_USEPASVADDRESS, false);
ftp_pasv($ftp, true);

ixudra get to localhost

I try to send curl to localhost with package called ixudra in laravel.
here is the code :
$url = 'localhost/fa_quality/public/api/qualities';
$response = Curl::to($url)
->enableDebug('./logFile.txt')
->get();
return $response;
but it's always return like below :
I tried my end point API postman, it work fine.
I try another end point such as https://jsonplaceholder.typicode.com/posts with withProxy method in ixudra and it work fine.
Im using xampp version 3.2.2. my computer run under proxy.
what am I doing wrong ?
I strongly doubt this has anything to do with the package. Most likely it's your setup. Usually when I see this, it's because your local webserver doesn't know how to interpret the "localhost" URL that you're using. Your Postman is an app that "lives" inside your host OS (I'm assuming Windows), which knows that an http request for "localhost" needs to be redirected to the VM instead of the internet.
I don't know xampp very well, but I work on Mac with an Ubuntu VM using vagrant. I'd fix this by SSH-ing into my VM and editing the hosts file to redirect HTTP calls FROM the VM to url "localhost" back TO the VM itself by adding the line 127.0.0.1 localhost. I would assume you can do something similar on xampp, but no idea how it works, sorry.

Php code not executing on web browsers [duplicate]

I just did a fresh install of Apache server 2.2.
Everything works. When I go to localhost I get: "It Works!"
I just installed mySQL5.5 and when I go to localhost:3306 I just get gibberish:
J���
5.5.22�'���4[LM{D~p�ÿ÷!�€����������6[I=4/+,9z{|�mysql_native_password�!��ÿ„#08S01Got
packets out of order
I see many posts on the internet with users with similar problems, but I can't figure out a solution.
Can anyone help?
The mysql service is not a web interface - you cannot connect using a browser. You will need to install a mysql client of some kind.
If you try to start phpmyadmin then do it like this:
localhost/phpmyadmin
I'm a jsp beginner.
I have a same problem with you.
I guess it's kind of port problem.
For me, I had set the port for Apache server connector as 9090.
Later, when I installed mysql, the port for mysql was 3306 as its default port.
In my jsp file,
i loaded jdbc driver like 'jdbc:mysql://localhost:9090/dbname'
and then i call 'http://localhost:9090/my.jsp' on my web browser.
That's when I got the same problem with you.
I fixed the port part in my jsp file like 'jdbc:mysql://localhost:3306/dbname'
and I could get it all right.
I think you need to check the port for your Apache server.
You can check out \conf\server.xml file in your Apache directory.
The part starts with "Connector port=8080...." in server.xml file.
If so, you need to put 'http://localhost:8080... on your browser.
Try just to write http://localhost/ without the port and it will work , Or go to your phpmyadmin and click on My websites and it will take you immediately to your localhost
I'm having exactly the same problem, so far I have :
1)Manually changed the Collation (it seemed to be defaulting to cp850)
2)altered the ini/cnf file (located under services.msc -> MySQL)
3)Changed the max_packet_size to 2G
3)rebooted the server.
As a start to this please run this script from MySQL
'SHOW VARIABLES WHERE Variable_name LIKE 'character_set_%' OR Variable_name LIKE 'collation%';'
It should bring up a table of your collations, they should all read utf8
Possible causes

HTTP Get with variables

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

Why is the same CURL code failing on one server and yet works on the other one?

The code attempts to grab a test page for example Yahoo.com in this case. I am outputting the var_dump
http://jinimatics.com/test.php (this works)
http://jinimetrix.com/test.php (this does not)
(Curl is installed on both servers along with fairy recent Lamp Stack)
Try to compare whats installed and version differences.
check your server settings with phpinfo();
then you can change settings in php.ini

Categories