Maybe I should ask this question in the Ubuntu section instead, but don't really know where the problem is so I'm trying here first.
I'm trying to learn how to use SQL database through a webserver, and I've used this tutorial: Link
I've done everything like in the tutorial, but I'm using Ubuntu server, not windows.
The problem is that the app is not able to display or create any entries from/in the database. I use PHPMyAdmin to manage the SQL database.
1. So my main question: Is there any difference between WAMP/LAMP? Or can I use the same approach?
If the answer is YES, then I have some more questions:
I'm using the default location for my server /var/www/ and have put all the .php files there? Correct?
When he makes the db_config.php he uses "localhost" but I want to use my ip instead, do I just have to change "localhost" to "81.xxx.xxx.xxx" or do I need to add something more?
As you can see I'm not really sure where the problem is, if it's the compability between the tutorial and the LAMP server instead of WAMP, or if it's the config of the connection, something in the php codes, the placement of the php files or whatever?
It's so frustrating because I don't know where to start.
Thank you in advance!
EDIT:
I can access the php files on the server so no problem there.
This is from my access.log file when trying to list all items: [09/Oct/2013:16:56:07 +0200] "GET /var/www/get_all_products.php? HTTP/1.1" 404 450 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"
This is when I try to create a new product: [09/Oct/2013:19:26:14 +0200] "POST /var/www/create_product.php HTTP/1.1" 404 448 "-" "Apache-HttpClient/UNAVAILABLE (java 1.4)"
And this if from the error.log file when trying to list all items: [Wed Oct 09 17:01:51 2013] [error] [client 81.225.106.145] File does not exist: /var/www/var
I get the same error when trying to create a new product.
Can you guys make anything out of this??
Is there any difference between WAMP/LAMP? Or can I use the same approach?
Yes, there are differences - mostly related to networking and security. However, there's no reason the code in that tutorial wouldn't work Ubuntu.
Firstly, are you running both the web server and database on the same Ubuntu machine? If so, you can leave the "localhost" entry - you need to specify an IP address if the web server and database are on different machines. If everything's on the same server, that just complicates matters, and breaks when your IP address changes. You should certainly not use a public IP address (like 81...*), because then your traffic from the web server may well get routed out on the internet to reach your database.
Secondly, if PHPMyAdmin is running on the same server as your web app, there's no problem connecting from your web server to the database in principle.
Thirdly, have you tried accessing the URLs in a browser to see if they are working? If that doesn't work, the app can't won't be able to access them either. The tutorial mentions http://api.androidhive.info/android_connect/get_all_products.php - presumably you've changed that to http://IPAddressOfUbuntuServer/android_connect/get_all_products.php. First see if you can access that URL (to get it to go, you should put your files in /var/www/android_connect) via a browser, and work out what's going on. Once that works, try accessing that in the browser on the Android device; if that works, the app should too.
Related
I was using cpanel before, but I'm using Plesk Panel / Centos7 now. I moved my sites to Plesk Panel from CPanel. I'm runing file_get_contents() function, but it's not working on Plesk Panel.
Why? I dont know why. What should i do?
my code;
$data = file_get_contents('http://example.com');
this code is not working on Plesk Panel.
Thanks, best regards.
What is error message says?
if error message says, the stream (URL) requested cannot be opened. There are many possible reasons for this:
1. base URL is bad. $pc['pcname']
2. username and/or password are bad
3. username/password do not have permission on the server
4. Your system cannot reach the server (firewall, PHP permissions, ...)
I would use the following strategy to debug:
1. Dump $url and write it down.
2. Use a browser with debug tools (eg Firefox/Firebug) and try to access that URL.
3. Look at the headers returned to see what error the server reports (if any).
4. Think about why that error is returned
We have upgraded our hosting platform with latest tech stack which includes PHP updates from Version 7.0 to 7.3 and enabled SSL certification.
After the upgrade, one of our user authentication method has failed though, it was working till the hosting platform upgrade.
Here is copy of PHP code - codecheck.php,
<html>
<body>
<?php
$header = "Content-Type: application/json";
header($header);
$code = $_GET["code"];
$codelistFile = "./codelist.txt";
$codeList = file( $codelistFile, FILE_SKIP_EMPTY_LINES);
$codelistOutput = sprintf('%s%s', $code, "\r\n" );
file_put_contents( $codelistFile, $codelistOutput, FILE_APPEND);
?>
</body>
</html>
Here is result of codelist.txt before the platform upgrade (with PHP version 7.0)
65cafead50f6d205d66f90c74f1683344ca86c8cc60fc0370c278ecb880da5c8
6e85e436538335da64f6e9172bd4191686e591aa390cca69acb9346668a48bd5
Here is result of codelist.txt after the platform upgrade (with PHP version 7.3)
774cad9dd07761fe79db8baa9370a3dd84abca558c73c1f46b39e7c996a26d70?code=774cad9dd07761fe79db8baa9370a3dd84abca558c73c1f46b39e7c996a26d70
f10bb27fb82b0d539d3607012655012764c60794cc656aa6912eccc16d927a82?code=f10bb27fb82b0d539d3607012655012764c60794cc656aa6912eccc16d927a82
Here is value of code repeated along with 'code' text itself hence the value of 'code' does not match when it compared.
Here is what I can see in ssl_access log files, ssl_access.log-20190629:79.1.200.79 - - [29/Jun/2019:07:46:24 +0100] "GET /codelist.php?code=ae21250db8b20cac3b7016e6d36a63de5846d537f032ed841a3e5c9121202cf4?code=ae21250db8b20cac3b7016e6d36a63de5846d537f032ed841a3e5c9121202cf4 HTTP/1.1" 200 19 "-" "Registration"
From this log file, I can see all GET requests to server appending the data twice.
I would expect it would be something like,
example.com/?code=123456789
but not as
example.com/?code=123456789?code=123456789
I am very new to PHP and HTTPS stuff, please help to figure out the issue. Thank you.
Here is an update:
As suggested, the issue seems to be more with SSL re-writing,
Here is code from desktop app where the app will connect and check the code with the server,
C++:
CString RegistrationServer::Uri( CString page, CString code )
{
CString sServer;
sServer.Format("http://www.mywebsite,com/%s?code=%s", page, code);
//Here page=codecheck.php and code = 10;
return sServer;
}
Here is log when submitted through desktop app,
27.62.66.34 - - [30/Jun/2019:21:55:51 +0100] "GET /codecheck.php?code=10?code=10 HTTP/1.1" 200 - "-" "Hack-o-Matic ver 0.01"
I can simulate the same request through web browser as below,
https://www.mywebsite/codecheck.php?code=10
Here is log when submitted through web browser,
27.62.66.34 - - [30/Jun/2019:21:46:28 +0100] "GET /codecheck.php?code=10 HTTP/1.1" 200 - "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"
You can see the difference in both the request is http vs https.
When the request is coming from desktop app, the code data is appended twice which uses http.
It appears that changing desktop app to have https will help fix the issue but that's something that we can't do anything with desktop app.
So we have to relay on fix from Server side but our hosting company doesn't seem to understand the problem exactly.
They keep analysing the issue since last 3 days and coming up some fixes like googleapi call fixes but that's not helping to fixing up our real issue.
I'm not sure if I'm missing some better phrases/terms to explain this issue to them better. Please let me know if there is better way to explain the issue to our hosting company.
If nothing working out, Can I ask them to remove SSL certification?
Another Update:
Here is response from our hosting company,
We have this referred to our engineers and they confirmed that this only happens when calling http and not https. You need to use https now since you have enabled SSL.
Latitude-E6540:~$ curl -I http://www.mywebsite.com/codecheck.php?code=10
HTTP/1.1 301 Moved Permanently
Server: nginx/1.15.8
Date: Mon, 01 Jul 2019 11:03:47 GMT
Content-Type: text/html
Content-Length: 169
Connection: keep-alive
Location: https://www.mywebsite.com/codecheck.php?code=10?code=10
Strict-Transport-Security: max-age=15768000
Our engineers made some tests and they were not able to replicate when they set to https.
Latitude-E6540:~$ curl -I https://www.mywebsite.com/codecheck.php?code=10
HTTP/1.1 200 OK
Server: nginx/1.15.8
Date: Mon, 01 Jul 2019 11:03:35 GMT
Content-Type: application/json
Connection: keep-alive
Strict-Transport-Security: max-age=15768000
Here is log from server,
213.171.217.184 - - [01/Jul/2019:12:03:35 +0100] "HEAD /usage7.php?code=10 HTTP/1.1" 200 - "-" "curl/7.58.0"
They confirmed that this looks to be something with your local software settings as this only seems to get in the case of "after submitting the requests through browser, HTTP GET data is not appended twice but when the same is submitted through their desktop software, the HTTP GET data is appended twice"
What I wanted to ask you is, from below curl output itself where I can see the code is appended twice when request is made with http, Does this having any clue to spot where the issue resides?
Location: https://www.mywebsite/codecheck.php?code=10?code=10
How to solve PHP upgrade errors:
Post-event, how to find, diagnose and fix errors apparently caused by PHP updates?
1) Check your scripts for PHP Errors.
2) Check changes to your php.ini file caused by updates.Depending on your system and upgrade method, the php.ini file may be adjusted or even a new default one. Read the Migration Notes to see if this may apply to you. You will need to review and explore what's changed. Also manually compare your reserved/backup php.ini with the current/new live one.
3) Read the PHP Migration notes for each version you have upgraded into and then out of(These are best done from oldest to newest).
4) Read the corresponding PHP Changelog(s) and search this text (it's loooong) for the functions you've found be failing in step (1).
For your specific instances; your code is of a very low quality (you are sending HTTP heders after you are sending HTML code) so the issue may well be caused by PHP upgrading an already existing error from E_WARNING to E_ERROR, or similar.
Low quality code is most easily fixed by turing on error_reporting(E_ALL); either in the scripts or in the php.ini and reading the resulting error logs.
Good Luck.
Update
Even with this SSL log, I can see the value for code twice and the same written to the file. I would expect it would be something like example.com/?code=123456789 but not as example.com/?code=123456789?code=123456789.
The sign you have two ? means you should be exploring the code that sets the code= value, please update your question with this information, how is code set?
Your issue may be with your HTTP Host routing, Apache, Nginx, etc., your HTTP Host is possibly double loading, first the HTTP_ page and then secondly redirecting on to the HTTPS page with the original query string appended, thus appending twice.
I think one or both of the above is where your problem lies.
Update 2:
Comment by Thi:
Here is what my hosting company responded, "as per our engineers the cause of the logs is de to the website making http (not https) calls to the google api for css and other things. They have advised that you need to ensure that any code that relates to http is switched to https." - There is below line in all of our html pages and have changed it to https but it didn't help <link href="fonts.googleapis.com/…" rel="stylesheet" type="text/css">
This relates to what I reference above about checking your server routing for HTTP and HTTPS protocols.
Solutons:
1) Update all your outgoing links to https:// (or simply //) so:
<link href="//fonts.googleapis.com/..." rel="stylesheet" type="text/css">
will always connect securely, if loaded securely.
2) Use Content Security Policy (CSP) Upgrade Insecure Requests flag to do just that; to force all http:// links within your website to be turned into https:// links by the client browser.
In your .htaccess, or equivilant file:
Content-Security-Policy: upgrade-insecure-requests;
However, insecure calls to 3rd party resources will NOT be the cause of your code block being appended to your URL twice.
A quick question. I have two laptops, installed with WAMP, both using MYSQL.
I tried ping each other -> success
Configure the phpmyadmin -> require and allow ip addresses ->success
View phpmyadmin of another pc typing 192.168.0.*->succes
But when i tried to putting php code on laptop A with '192.168.0.*' as host , it came out an error, saying server not responding, run time error...
Try giving the following line in the mysql configuration file. And make sure the privilege is there for the user.
bind-address=YOUR-SERVER-IP
Running Windows 7 Ultimate / Apache 2.4.9 / PHP 5.5.11 / FireFox 29.
When I try running the Google PHP API example user-example (using FireFox) I am able to connect and receive the approval page for the URL Shortener. However, when I click on the Accept button I receive the message:
"Firefox can't establish a connection to the server at localhost"
netstat showed that only Apache was listening on port 80. So, thinking that this might be a call-back issue, I ran a REST script (using the same credentials) that did pretty much the same thing, i.e. queried OAuth etc. This worked successfully.
NB: IE11 fails at the same point with a "This page can’t be displayed"
message, the offending URL being https://accounts.google.com.
Any assistance greatly appreciated.
Not sure if this will help, and its to big for a comment but try this
Changing the following PHP.ini settings:
Uncomment the extension=php_openssl.dll - necessary for 'https' URLs;
Set the time-zone. Google is fussy about times, so this might have affected the outcome.
I finally resolved the issue, much to my chagrin.
With all the other URI's in the example being "https://" I inadvertently set the call-back's URI to
https://localhost/etc
The solution was to set the call-back's URI to an 'http', i.e.
http://localhost/etc
I moved a PHP website from win2003sp2 Standard to win7 Enterprise. Nothing changed. The website works correct in win2003. But in win7 when get service status via win32_query_service_status(), return WIN32_ERROR_ACCESS_DENIED.
I can not figure it out.
As link provided by Dan, I know Win2003 is different from later Windows for remote authenticated users. Is it the root cause that I cannot get the service status via my website page?
Quote: Windows Server 2003 and Windows XP: Remote authenticated users are granted the SC_MANAGER_CONNECT, SC_MANAGER_ENUMERATE_SERVICE, SC_MANAGER_QUERY_LOCK_STATUS, and STANDARD_RIGHTS_READ access rights. These access rights are restricted as described in the previous table as of Windows Server 2003 with SP1
The access right are restricted as of win2003sp1. But the Website works correct on win2003sp2. I think it may be not the root cause.
The user that PHP is running as does not have the correct rights to the SCM database. See here for more information: http://msdn.microsoft.com/en-us/library/windows/desktop/ms685981(v=vs.85).aspx
WIN32_ERROR_ACCESS_DENIED error is "The handle to the SCM database does not have the appropriate access rights" mentioned on php.net.
check current user permission to folder that may be help ..
Finally, change the authentication of the folder where win32_query_service_status() located as below solved my problem.
Anonymous Authentication - Disabled
Windows Authentication - Enabled