Closed staebchen0 closed 5 years ago
Hi Anja,
try to create an empty file named "token" in the folder C:\wamp\www\Home\
Any difference?
Hi Matthias,
i create an empty file token.txt but there ist no difference. It was a long time before the same message came again.
Gruß Anja
It must be named just "token" without file extension.
okay, now comes only the message: Curl Failed
If you have a default install of the WAMP stack you may not have CURL enabled. Try:
Close WAMP Navigate to WAMP\bin\php(your version of php)\ Edit php.ini Search for curl, uncomment extension=php_curl.dll Navigate to WAMP\bin\Apache(your version of apache)\bin\ Edit php.ini Search for curl, uncomment extension=php_curl.dll Save both Restart WAMP
239/5000 in both ini files I have extension = php_curl.dll entered. In the php.ini of Apache this entry already existed. not in the php.ini. After the restart of wamp, however, I get the same message as above ....
A hunch... try adding these lines:
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
after this line:
$ch = curl_init($endpoint."/api/auth/login");
If that works, it means the WAMP stack isn't configured to properly deal with SSL secured sites.
Now this error comes: Notice: Undefined index: data in C:\wamp\www\Home\login.php on line 23
here the line 23 bold: if($result['data']['token']) { print "New Login Successful for ".$result['data']['user']['first_name']." ".$result['data']['user']['last_name']."!\nToken: ".$result['data']['token']; $token = $result['data']['token']; file_put_contents("token",$token); } else { die("Login Failed!\n"); }
print "\n";
Looks like you're not receiving a successful login response from the API. Have you put the correct email_address
and password
for your SurePet login in a file called config.php
? (That should be a copy of the config.php.dist
that you edit with your details.)
Also, you'll either need to fix your WAMP setup, or put that curl change I showed you in every page so it ignores SSL. (The latter being the wrong way to deal with it!)
yes, I have created a copy of the file "config.php.dist", entered my e-mail address and PW and saved the file under the name "config.php".
When I enter the credentials on the page: https://www.surepetcare.io/ enter, then the access works.
I'll try to reinstall wamp, maybe I made a mistake here.
One last thing - try deleting that token file and trying again - when the code is working, it will create that file when it is needed.
If I delete the file, comes again the first error message:
Warning: file_get_contents(token): failed to open stream: No such file or directory in C:\wamp\www\Home\login.php on line 7
I think I have to deal with the PHP installation and Wamp installation again Is there perhaps a guide for the windows installation?
That warning is fine though - it is just a warning- it doesn’t impact the running of the code. What happens after that warning?
I just tried the raw code on PHP in Ubuntu under Windows and it behaves as expected.
So, Wamp is reinstalled. PHP. ini file Curl is active. I get another message now when I run login.php: Parse error: syntax error, unexpected 'logout' (T_STRING) in C:\wamp64\www\home\login.php on line 9
the token file was not created again. I have created these again, but get the same message as without a file
Line 9: include 'logout.php'; The File is in the home folder!
One more note: I did not install Ubuntu. I try the whole thing with a Windows operating system.
What version of Windows and what version of WAMP did you install? Where did you download WAMP from?
Windows 8.1 - 64 bit WampServer Version 3.1.7 64bit Download WAMP: http://www.wampserver.com/en/download-wampserver-64bits/ Apache 2.4.37 Port 80- PHP 7.2.14 MySQL 5.7.24 Port 3306 MariaDB 10.3.12 Port 3307 PHP 5.6.40 for CLI (Command-Line Interface)
Info: I have only installed the included PHP etc. components of WAMP. No PHP, CURL additionally installed
Cool. Busy today, but I’m genuinely curious as to what is happening here so will spin it up and take a look. (This isn’t even my repo/code!)
Great, thank you for your help :-)
Hi,
I tested the following: Value set to 2 curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, 2);
Then a token was created (in the file "Token")
If I then set the parameter back to 'false': curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, False)
Report: Found Old Session Token. Attempting Logout ... Token Invalid / Expired! New Login Successful for Test Python! Token: eyJ0eXAiOiJKV1QiLCJhbGciZGV2aWNlX2lkIjoiMjU1Nzc3NzIwNCJ etc ....
Value set to 1: curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, 1);
1 | 0.0012 | 401176 | {main}( ) | ...\login.php:0 2 | 0.5749 | 402992 | curl_setopt ( ) | ...\login.php:10
New Login Successful for Test Python ! Token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.....etc.
I tested the following: curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE); curl_setopt($ch, CURLOPT_CAINFO, "C:/wamp64/apps/phpmyadmin4.8.4/libraries/certs/cacert.pem");
Report: Found Old Session Token. Attempting Logout... Token Invalid/Expired! Curl Failed
which I do not understand: the login has supposedly worked and the token is displayed.
The same token is also in the file - and yet I can not run another script successfully.
Example: getCurfewStatus.php
Found Old Session Token. Attempting Logout ... Token Invalid / Expired! New Login Successful for Test Python! Token: eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9 ...... etc.
Okay, here's what you need to do: with a clean install of WAMP Server, and with the code from the sureflap repository with NO changes:
git clone
to download this repository.config.php
by copying config.php.dist
and adding email and passwordcacert.pem
from https://curl.haxx.se/docs/caextract.htmlcacert.pem
in PHP directory of choice, in my case: C:\wamp64\bin\php\php7.3.1
php.ini
and edit:
curl.cainfo = C:\wamp64\bin\php\php7.3.1\cacert.pem
openssl.cafile= C:\wamp64\bin\php\php7.3.1\cacert.pem
Note that opening php.ini
from the WAMP Server tray icon opens phpForApache.ini
in the related PHP directory (in my case C:\wamp64\bin\php\php7.3.1
) you also need to edit php.ini
in the same directory.Following these steps, the code in the repo works without any changes.
Basically we just configured PHP on Windows to behave as it would out of the box on a Linux host!
Hope that helps.
Install Wampserver 3.1.7 64 bit x64. - installed
Run git clone to download this repository. - download zip file and extract in C:\wamp64\www\sureflap-master
Create config.php by copying config.php.dist and adding email and password - copying onfig.php.dist an change E-Mail und password
Download cacert.pem from https://curl.haxx.se/docs/caextract.html - Download cacert.pem and saving in C:\wamp64\bin\php\php7.3.1
Update php.ini and edit: - curl.cainfo = C:\wamp64\bin\php\php7.3.1\cacert.pem openssl.cafile= C:\wamp64\bin\php\php7.3.1\cacert.pem
The same do with: C:\wamp64\bin\apache\apache2.4.37\php.ini
Restart all WAMP Server services - newstart
Aufruf: http://localhost/sureflap-master/login.php Antwort: ! ) Warning: file_get_contents(token): failed to open stream: No such file or directory in C:\wamp64\www\sureflap-master\login.php on line 7
1 | 0.0004 | 400088 | {main}( ) | ...\login.php:0 2 | 0.0007 | 400184 | file_get_contents ( ) | ...\login.php:7
I dont understand ;-(
here the php.ini with changes:
[curl]
; A default value for the CURLOPT_CAINFO option. This is required to be an
; absolute path.
curl.cainfo = "C:\wamp64\bin\php\php7.3.1\cacert.pem"
[openssl]
; The location of a Certificate Authority (CA) file on the local filesystem
; to use when verifying the identity of SSL/TLS peers. Most users should
; not specify a value for this directive as PHP will attempt to use the
; OS-managed cert stores in its absence. If specified, this value may still
; be overridden on a per-stream basis via the "cafile" SSL stream context
; option.
openssl.cafile= "C:\wamp64\bin\php\php7.3.1\cacert.pem"
I think creating the token file does not work. for whatever reason...
when I create the file and login.php calls comes again Curl Failed
Two things-
One: you didn’t update the two php.ini
files I mentioned. You updated one in an Apache directory instead. Look for the path to the php version you’re using and update both php.ini
and phpForApache.ini
.
Two: are you trying to open these scripts in a web browser? I suspect they were written with the command line in mind, and that’s how I’ve been testing them.
From a command line try running:
<path to php.exe> login.php
okay, I understand, but apart from the included php installation in WAMP I have no further PHP installation on the machine. That's why I only adapted the php.ini in the WAMP directory. This phh.ini File in: C:\wamp64\bin\php\php7.3.1 and C:\wamp64\bin\apache\apache2.4.37\bin
I thought the php installation that comes with WAMP is enough. Then I will install PHP And yes, I execute the commands in the browser. I'll test that first now
Thank you for your patience :-)
If you did a standard install of the WAMP Server you already have everything you need. You can open a command prompt, navigate to where you put the repo files and run:
C:\wamp64\bin\php\php7.3.1\php.exe login.php
You can make this easier by adding the php path to your path environment variables. Then you can just run:
php <anyfile>
from any location.
well, I have yet discovered a mistake. I have made the changes to the php.ini version 7.3.1. In the WAMP server, however, version 7.2.14 was active.
If I now execute the command in the DOS window, the following message appears:
C:\wamp64\bin\php\php7.2.14>php.exe C:\wamp64\www\sureflap-master\login.php
PHP Warning: file_get_contents(token): failed to open stream: No such file or directory in C:\wamp64\www\sureflap-master\login.php on line 7
Warning: file_get_contents(token): failed to open stream: No such file or directory in C:\wamp64\www\sureflap-master\login.php on line 7
PHP Fatal error: Uncaught Error: Call to undefined function curl_init() in C:\wamp64\www\sureflap-master\login.php:14
Stack trace:
#0 {main}
thrown in C:\wamp64\www\sureflap-master\login.php on line 14
Fatal error: Uncaught Error: Call to undefined function curl_init() in C:\wamp64\www\sureflap-master\login.php:14
Stack trace:
#0 {main}
thrown in C:\wamp64\www\sureflap-master\login.php on line 14
Put the source files (this repo) somewhere under your Documents directory and try again.
It doesn't matter which version of PHP you use, you just need to be sure that:
If you don't care about using PHP and just want to see data from the cat flap on Windows, try these Powershell scripts: https://github.com/hdurdle/sureflap
so, now i have wamp reinstalled and the change php. ini and phpForApache.ini made.
now it seems to work if I run the command at DOS level :-)
I would like to thank you very much for your help !!!!
Great - @alextoft I think you can close this now. Not an issue with your code! :)
Thanks to Howard
Hi everyone, i am new and i do not know php. When trying to establish the connection, I get the following message:
where is the mistake? Is the call in code line 7 wrong? If so, how should I change this?
System: Windows 8, PHP7, wamp 3.1.3
Best regards Anja