What is localhost path for accessing server file in android?? - php

I want to send variable from android application to wamp server and retrieve data from server. Please suggest me and what is path of localhost for wamp server. I am using "localhost/TestAndroid/check.php". The error is occurred data is not parsed.
Please suggest me with code. How to accessing data from android application(JSON+Android+HTTPClient)?.
Thanks
Nitin

Use this localhost address in your code '10.0.2.2/TestAndroid/check.php'
For more Help:
http://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/

Find the below link, it may help full
WAMP server

Follow these steps.
Make sure your PC and Phone are in the same network (Connected to the same wi-fi)
Open a command prompt and run ipconfig and get the IP adress. 99% chances are it'll be something like 192.168.X.X
Use this IP instead of localhost. i.e. 192.168.X.X/TestAndroid/check.php

Related

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

Check if PHP is running in local server

Well. I read some topics in SO but I not found a very specific answer.
I need to check with PHP if a PHP code is running in local or remote host. Currently I check with $_SERVER['SERVER_NAME'] but it is inconsistent. In this case, if I run PHP with listed IPs like 127.0.0.1 or localhost it'll consider local, otherwise remote. If I share my IP with a friend, my code still local, but it consider remote because the shared IP isn't listed.
Well, I think that check IP for localhost is not a good idea (except if you know a good method). I tried methods like gethostbyaddr() and gethostbyname() but don't work correctly too.
I don't have a PHP code to show, but my code is basically that:
// true = localhost
return $_SERVER['SERVER_NAME'] === '127.0.0.1';
The fundamental question is: what can determine that PHP is running local? What is "local" for PHP? I think that it can solve the problem.
Obs.: I don't have access to CMD/Shell with PHP.
You could do what most PHP frameworks do and set a flag during your app's bootstrap phase that defines which environment the code is running in. In it's simplest form:
// the setting when run on a dev machine
define('ENV', 'local');
Then it's a simple case of:
if ( ENV == 'local' )
{
// do stuff
}
This is how I do it, which I find more reliable than trying to detect for 127.0.0.1:
if( strpos(gethostname(), '.local') !== false ) { }
Basically, the hostname's on my workstations all have .local appended to it. You can change this to match your workstation's hostname entirely.
Check $_SERVER['REMOTE_ADDR']=='127.0.0.1'. This will only be true if running locally. Be aware that this means local to the server as well. So if you have any scripts running on the server which make requests to your PHP pages, they will satisfy this condition too.
If someone is visiting your site via the web, the IP address you see will never be 127.0.0.1 (or ::1 for IPV6), regardless of the usage of a proxy. (Unless of course you're running the proxy yourself on the same server ;)
As far as I know, only you will be able to know what addresses are local or not. Your network could be set up with IP addresses that don't look local at all. PHP cannot as far as I know determine this by itself.

MAMP - Not working for my iPhone on the same Network

I've been googling this one a lot but I still could not make it work. I have a MAMP web server installed on my mac and I've created some a web service. It work fine when I call it from the browser on my mac when I use localhost:8888/myfile.php and also when I use 192.168.0.108/~martin/myfile.php.
The problem is when I try to call the 192.168.0.108/~martin/myfile.php from my iPhone to do some testing, the requests time out. It is really weird because this was working 2 days ago. I'm not sure what has changed. I'm not very familiar with httpd.conf and htaccess files, but I did not change things there manually.
Any help would be appreciated!
Have you tried going to http://192.168.0.108:8888/myfile.php on your iPhone? If MAMP is running on 8888 you will need to specify the port to access it there.
Be sure to check your computer's IP too. It's possible that it changed over the last few days depending on your router's setup.
Also, make sure the iPhone is indeed on the same network as your local machine. Depending on your network setup, a subnet might not work either. I've driven myself crazy trying to connect to a box that was actually connected on a separate subnet.
Don't know if this helps anyone but I got this working by simply removing the ip host address and changing this to the wildcard. It started working straight away after this
I had success opening my local-folder by opening the host by the computer’s local hostname.
Solution 1: computer’s local hostname
Find your computer’s local hostname: macOS->System Preferences->Sharing->File Sharing
https://support.apple.com/et-ee/guide/mac-help/mchlp1177/mac
Near the "Computer's Name" you can find the info:
"Computers on your local network can access your computer at:
"mymac.local"
Opening the compuerts name "your_computers_name.local" in iOS-Safari worked for me:
http://[your_computers_name.local]
For example:
http://mymac.local
Solution 2: computer’s network address
Try it with the computer’s network address. If you select and activate file-sharing in the preferences you can find the network address. Looks like: "smb://name.example.com". Replace "smb" with "http".
Open the network address in iOS-Safari (connected via USB-Cable or Wifi):
http://[insert_your_computer_network_address]
For example you can access your files like:
http://name.example.com/myfile.php
This worked for me, too.
As an alternativ way to find the address write "hostname" in terminal of the host-computer:
$ hostname
This will return the host's name / network address.
Doesn't work?
Maybe you have to allow file sharing first? I don't know ...
macOS->System Preferences->Sharing->File Sharing: On

Writing a file into a local PC using IP address in PHP

How to create a PHP script that would create a file.txt on the local pc through an IP address, there is a given IP address and a port which I can pass through.
How could I achieve this?
Any help will be appreciated, thank so much.
You can either, FTP it to the local machine, or simply let a person download it as a file. The second solution is the easiest, but requires someone on the local machine to initiate the download. The first solution can be automated, but requires you to set up an FTP server on the local machine.
Header will help you output as a download for the client.
http://php.net/manual/en/function.header.php
FTP will help you upload through FTP.
http://php.net/manual/en/book.ftp.php
on linux:
cat >dooda.php <<EOF
#!/usr/bin/env php
<?php
file_put_contents('file.txt',file_get_contents("http://example.com/of_some_url.txt"));
EOF
php dooda.php

Why would ftp_connect() return false on production server if it works elsewhere for connecting to the same FTP server?

I have a script that uses ftp_connect() among other FTP PHP functions for uploading a file.
ftp_connect() works when executed on my local development server for connecting to a remote FTP server. The same script, when executed on the remote server does not work for connecting to the exact same FTP server.
Could somebody please point me in the right direction?
Thanks!
Here is the code:
error_reporting(E_ERROR | E_WARNING | E_PARSE);
$server = 'ftp.someserver.com';
$ftpConn = ftp_connect($server);
if(!$ftpConn)
echo 'failed';
else
echo 'success';
No errors are reported.
So if I understand it correctly then the script above is installed on the server that you're trying to access using FTP (ie. the script is opening a local FTP connection)? What's the use? FTP in PHP is only useful to transfer files between 2 servers, you cannot use it to transfer files from the client to the server (since the script is executed on the server).
edit
Something I didn't add in my original comment : you could use a Java FTP applet if you want to transfer files from the client to the server. But be aware of the security issues involved (because the user credentials can be sniffed :p).
Probably firewall issues. On top of that, FTP was not designed with NAT in mind.
Try to login to the production server and use a ftp client to do the same connection.
I do not know the things inside it very well but I want to give my little help.My server is ubuntu Linux with Apache、PHP and MySQL,and my develop env is MAMP on Mac.
I met the problem suddenly and cannot find what happened because it was worked yesterday,I searched many answers and can't solved it.The ftp_connect($ftp_server) only return bool(false),but I can use my FileZilla,interesting,is it?
So I try to connect the server from my command line,like ftp 111.22.333.44,It shows:
500 OOPS: cannot read user list file:/etc/vsftpd/vsftpd.user_list
I login in my ubuntu server, and didn't find the vsftpd directory,and the vsftpd.user_listis in the directory /etc/,still don't know what happened.
So I simply create the directory and copy the file vsftpd.user_list to it.Then I try ftp 111.22.333.44(your IP address) again and it works now.
hope it help someone else.

Categories