Facebook Connect from Localhost, doing some weird stuff - php

So maybe the documentation is out of date, or I am just off here. But I have done a slew of FB iframe apps (connect), but I am starting my first FB Connect site. Running it from localhost, and the Connect URL is http:// my_external_IP_address. When I click on the FB login button on my site, it pops up, says waiting for facebook, and it returns my site in that box, with the URL up top with the http:// mysite/?session={session key, user_id, etc.} The user_id is infact my FB id. And so it thinks I am logged in. If I close the popup, I'm not logged in. I'm not sure why the pop up isn't doing the normal fb connect dialog. I'm following these steps.
(I added spaces to the http:// as to not be detected as 'spam')
html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml"
right after <body> <script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript">
At the end, before the body close tag: script type="text/javascript">
FB.init("fbkey", "http://127.0.0.1/xd_receiver.htm");
I have tried using xd_receiver.htm, /xd_receiver.htm (and other combos), and that brings up a blank page. using the http://127.0.0.1 at least does something.
In my config file, which is called before all of those, it checks for a PHP session key
to see if they are logged in, if that doesn't exist it looks for a cookie, and if that doesn't exist it does this:
require_once('includes/facebook.php');
$facebook = new Facebook($fbkey, $fbsec);
$user_id = $facebook->get_loggedin_user();
if($user_id > 0){
$user = $ac->getUserFromFB($user_id);
$_SESSION['user_id'] = $user['user_id'];
}
The user_id is always empty when I echo it out to the screen to test. The session event never occurs as well. So I don't know what it is doing in the popup, but I think Facebook thinks it is logging me in. Not sure. Pretty stumped on this one. Any help would be appreciated. Thanks!

I've personally found the easiest way to deal with facebook connect is to use winscp to sync my localhost to a server with a domain somewhere. Since fb connect is attached to an application, that application needs to be bound to a domain, which is where the api key gets generated. Somewhere in there, your localhost isnt working, unsurprisingly.

I don't know for sure but I suspect the problem is due to you running on your local machine.
My guess is that the Facebook server won't be able to find your machine on 127.0.0.1 as that is a local ip address. You could try using somewhere like whatisyourip.com to get your actual remote ip and use that instead but even then you would need to make sure that you have the necessary port forwarding set up for the FB server to be able to get to your local machine.
All in all, for this kind of site I think it would be easier to develop on an external server rather than a local environment.
Incidentally, I don't have to enter the second parameter for FB.init() - I just use
FB.init(fbkey);
If you haven't already, you could try taking that out completely to see if it helps.
Also I think that the script tag to include the facebook FeatureLoader.js should be before your </head> tag not after the <body> tag

Try editing your hosts file to point a hostname (doesn't matter what it is, as long as you set it as the hostname associated with your app in the settings) to 127.0.0.1, and then restarting your browser and visiting your local app via the domain you set in the hosts file. This should allow you to test most FB-related features. The main exception will be the Like button, because it depends on Facebook's servers also being able to access your app at the domain in question.
Example hosts line:
127.0.0.1 www.example.com
If you add the above you your /etc/hosts and restart your browser, you can replace the "127.0.0.1" component of the URL you're testing with www.example.com and it will be as if the domain associated with your app were indeed www.example.com

Related

Website to read file on diff raspberry pi and display values based on variable

I'm trying to create a website and 2 raspberry pi's that will connect to the website.
The goal is:
rpiA's display will be different from rpiB.
I'll put a file on each rpi containing their name. When I visit the website using rpiA, rpiA's name will be displayed (vice versa).
What I did is I placed a file in var/www/html/name.php
<?php
$xname= 'RPI-001';
echo $xname;
?>
Then on the website I placed:
$device_name = file_get_contents('http://127.0.0.1/name.php');
echo $device_name;
However, the result is always empty. I checked the allow_url_fopen and it is On. The reason maybe the 127.0.0.1 is broad and it needs a specific ip?
I also tried curl but the result is Error 404.
Is there another way to do this?
I did not consider login or session since I'm using a small screen in rpi and it will be hard to type without vnc.
127.0.0.1 is the IP of the system running the request. If you run that file_get_contents on any central server and access this using a browser, it will always access the server itself.
If you want to access any website on the system that is accessing the website, you need to use the IP address of the client, like file_get_contents('http:/' . $_SERVER['REMOTE_ADDR'] . '/name.php')

Getting name of logged in Windows user via Php on Apache [duplicate]

I have a PHP web application on an intranet that can extract the IP and host name of the current user on that page, but I was wondering if there is a way to get/extract their Active Directory/Windows username as well. Is this possible?
Check the AUTH_USER request variable. This will be empty if your web app allows anonymous access, but if your server's using basic or Windows integrated authentication, it will contain the username of the authenticated user.
In an Active Directory domain, if your clients are running Internet Explorer and your web server/filesystem permissions are configured properly, IE will silently submit their domain credentials to your server and AUTH_USER will be MYDOMAIN\user.name without the users having to explicitly log in to your web app.
I've got php mysql running on IIS - I can use $_SERVER["AUTH_USER"] if I turn on Windows Authentication in IIS -> Authentication and turn off Anonymous authentication (important)
I've used this to get my user and domain:
$user = $_SERVER['AUTH_USER'];
$user will return a value like: DOMAIN\username on our network, and then it's just a case of removing the DOMAIN\ from the string.
This has worked in IE, FF, Chrome, Safari (tested) so far.
Look at the PHP LDAP library functions: http://us.php.net/ldap.
Active Directory [mostly] conforms to the LDAP standard.
We have multiple domains in our environment so I use preg_replace with regex to get just the username without DOMAIN\ .
preg_replace("/^.+\\\\/", "", $_SERVER["AUTH_USER"]);
If you're using Apache on Windows, you can install the mod_auth_sspi from
https://sourceforge.net/projects/mod-auth-sspi/
Instructions are in the INSTALL file, and there is a whoami.php example. (It's just a case of copying the mod_auth_sspi.so file into a folder and adding a line into httpd.conf.)
Once it's installed and the necessary settings are made in httpd.conf to protect the directories you wish, PHP will populate the $_SERVER['REMOTE_USER'] with the user and domain ('USER\DOMAIN') of the authenticated user in IE -- or prompt and authenticate in Firefox before passing it in.
Info is session-based, so single(ish) signon is possible even in Firefox...
-Craig
You could probably authenticate the user in Apache with mod_auth_kerb by requiring authenticated access to some files … I think that way, the username should also be available in PHP environment variables somewhere … probably best to check with <?php phpinfo(); ?> once you get it runnning.
If you are looking for retrieving remote user IDSID/Username, use:
echo gethostbyaddr($_SERVER['REMOTE_ADDR']);
You will get something like
iamuser1-mys.corp.company.com
Filter the rest of the domain behind, and you are able to get the idsid only.
For more information visit http://lostwithin.net/how-to-get-users-ip-and-computer-name-using-php/
Use this code:
shell_exec("wmic computersystem get username")
Check out patched NTLM authentication module for Apache
https://github.com/rsim/mod_ntlm
Based on NTLM auth module for Apache/Unix
http://modntlm.sourceforge.net/
Read more at http://blog.rayapps.com/
Source: http://imthi.com/blog/programming/leopard-apache2-ntlm-php-integrated-windows-authentication.php
You can say getenv('USERNAME')
No. But what you can do is have your Active Directory admin enable LDAP so that users can maintain one set of credentials
http://us2.php.net/ldap
get_user_name works the same way as getenv('USERNAME');
I had encoding(with cyrillic) problems using getenv('USERNAME')
Referencing trying to also figure out if AUTH_USER is part of a particular domain group; a clever way to do this is t create a locked down folder with text files (can be blank). Set security to only having the security/distro group you want to validate. Once you run a #file_get_contents (<---will toss a warning)...if the user does not have group access they will not be able to get the file contents and hence, will not have that particular AD group access. This is simple and works wonderfully.
This is a simple NTLM AD integration example, allows single sign on with Internet Explorer, requires login/configuration in other browsers.
PHP Example
<?php
$user = $_SERVER['REMOTE_USER'];
$domain = getenv('USERDOMAIN');
?>
In your apache httpd.conf file
LoadModule authnz_sspi_module modules/mod_authnz_sspi.so
<Directory "/path/to/folder">
AllowOverride All
Options ExecCGI
AuthName "SSPI Authentication"
AuthType SSPI
SSPIAuth On
SSPIAuthoritative On
SSPIOmitDomain On
Require valid-user
Require user "NT AUTHORITY\ANONYMOUS LOGON" denied
</Directory>
And if you need the module, this link is useful:
https://www.apachehaus.net/modules/mod_authnz_sspi/
try this code :
$user= shell_exec("echo %username%");
echo "user : $user";
you get your windows(AD) username in php
I tried almost all of these suggestions, but they were all returning empty values. If anyone else has this issue, I found this handy function on php.net (http://php.net/manual/en/function.get-current-user.php):
get_current_user();
$username = get_current_user();
echo $username;
This was the only way I was finally able to get the user's active directory username. If none of the above answers has worked, give this a try.

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

Can I test paypal api's from localhost

UPDATE 1:
According to this tutorial on Using PayPal's Instant Payment Notification with PHP, PayPal cannot access locally hosted websites unless certain router ports are opened. Is this because the website is about IPN or is this true for all PayPal APIs?
ORIGINAL QUESTION:
On my laptop, I have a LAMP environment setup, when I use the http://localhost to create website before going live.
For a new project, I need to use the PayPal APIs. Will I be able to use the localhost to test the PayPal APIs if I connect my laptop to the internet? Or will I have to upload my website to a LAMP host elsewhere?
You're probably thinking, what a stupid question, just try it to see if it works. I have tried it and it's not working and I wanted to rule out this question before going onto the next step.
If you want to debug your IPN code, you'll need to make your server publicly available in some way. This is so PayPal can asynchronously post back to your server at a later time after you've submitted your request. Usually this is pretty quick I think (within 15 seconds) but it could be longer.
One easy way I've found to make a development server available publicly is to use a tunneling solution from this list, like boringproxy. This allows you to continue to develop in your IDE like normal, running your code in debug mode. When PayPal posts back to your endpoint, you can debug it right there in your IDE. These services wrap this up for you, so it's very easy to do without any technical know how.
From my understanding, this is done using a "reverse SSH tunnel" which allows your site to be made public by proxying it through a server that's already publicly available. Note that before you do this, you have to consider that not just PayPal can hit your site once it's made public, but anyone can, so please take that into consideration first.
Also, if you've got your own public facing domain and don't mind playing around in a terminal with SSH, you can supposedly do something like this shell script (copied from this gist)
# Usage: show <local-port> <subdomain>
function show() {
DOMAIN=".yourdomain.com"
REMOTE="$2$DOMAIN"
ssh -tR 1080:127.0.0.1:$1 vps "sudo ssh -Nl \$USER -L $REMOTE:80:127.0.0.1:1080 localhost"
}
To get this to work as above, you'd need to put the following in your ~/.ssh/config file:
Host vps
HostName <server address>
User <server username>
If you don't want to (or can't) do this, then the following will work:
SERVERUSER="<server username>"
ssh -l $SERVERUSER -tR 1080:127.0.0.1:$1 <server address> "sudo ssh -Nl \$SERVERUSER -L $REMOTE:80:127.0.0.1:1080 localhost"
If http://localhost doesn't validate use http://127.0.0.1
One simple solution is described in the official developers page of PayPal:
developer.paypal.com - Local IPN Testing
The trick consists on writing a small HTML file with this content:
<form target="_new" method="post" action="https://www.YourDomain.com/Path/YourIPNHandler.php">
<!-- start example variables: -->
<input type="hidden" name="SomePayPalVar" value="SomeValue1"/>
<input type="hidden" name="SomeOtherPPVar" value="SomeValue2"/>
<!-- /end example variables -->
<input type="submit"/>
</form>
To get the real results you need to copy all of the IPN variables which PayPal sends.
These real variables can be found into the PayPal account, under IPN History:
IPNs History
You need to click on the relative Message ID and then copy the "IPN Message" content (it will be something like mc_gross=27.00&invoice=Test-1&protection_eligibility=Ineligible&...) which must be converted into HTML hidden input fields.
For example:
<input type="hidden" name="mc_gross" value="27.00"/>
<input type="hidden" name="invoice" value="Test-1"/>
<input type="hidden" name="protection_eligibility" value="Ineligible"/>
....
After setting up all of these variables and changing the action URL, you can open the file with a browser and then submit this form.
It should work.
I have made a payment integration with paypal last year, and it worked on localhost without problems.
Are you using the paypal sandbox for development?
https://developer.paypal.com/
It should work without a problem, however it might get picky if you send in "invalid URLs" for return urls and IPN message urls. Meaning, sending in http://localhost/cancelpaypal.php as cancelURL might tell you that it is an invalid url.
I do however don't think it should.
Having to open up router ports would only be needed for IPN, because the redirect in the normal flow is a regular "Location:" header hence it is your browser that needs to be able to access the site (localhost)
Well, it most works, but also, you can setup a temporary local dns entry.
All you have to do is:
open your /etc/hosts
add a new entry: yourwebsite.com 127.0.0.1
So when your browser query for the website will be fetched from your 127.0.0.1, somethings your need to flush dns( /etc/init.d/nscd restart).
and that is it all, but remember to remove the entry when you are ready for production.
To use IPN your localhost has to be accessed from the web. One solution that definitly works is to use a virtual Machine, install VPN-Server, connect your Clinet via VPN and manage virtual host to redirect to your local IP-adress. That way, if you turn on VPN your server can be accessed from outside and IPN can be sent.

php access network path under windows

within PHP (XAMPP) installed on a Windows XP Computer Im trying to read a dir which exists on a local network server. Im using is_dir() to check whether it is a dir that I can read.
In Windows Explorer I type \\\server\dir and that dir is being shown.
When I map a network drive a can access it with z:\dir as well.
In PHP I have that script:
<?php if( is_dir($dir){ echo 'success' } ) ?>
For $dir I tried:
/server/dir
//server/dir
\server\dir
\\server\dir
\\\\server\\dir
and
z:\dir
z:\\dir
z:/dir
z://dir
But I never get success?
Any idea?
thx
I solved it by changing some stuff in the registry of the server as explained in the last answer of this discussion:
http://bugs.php.net/bug.php?id=25805
Thanks to VolkerK and Gumbo anyway!
I love stackoverflow and their great people who help you so incredibly fast!!
EDIT (taken from php.net):
The service has limited access to network resources, such as shares
and pipes, because it has no credentials and must connect using a null
session. The following registry key contains the NullSessionPipes and
NullSessionShares values, which are used to specify the pipes and
shares to which null sessions may connect:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters
Alternatively, you could add the REG_DWORD value
RestrictNullSessAccess to the key and set it to 0 to allow all null
sessions to access all pipes and shares created on that machine.`
add RestrictNullSessAccess=0 to your registery.
You probably let xampp install apache as service and run the php scripts trough this apache. And the apache service (running as localsystem) is not allowed to access the network the way your user account is.
A service that runs in the context of the LocalSystem account inherits the security context of the SCM. The user SID is created from the SECURITY_LOCAL_SYSTEM_RID value. The account is not associated with any logged-on user account.
This has several implications:
...
* The service presents the computer's credentials to remote servers.
...
You can test this by starting the apache as console application (apache_start.bat in the xampp directory should do that) and run the script again. You can use both forward and backward slashes in the unc path. I'd suggest using //server/share since php doesn't care about / in string literals.
<?php
$uncpath = '//server/dir';
$dh = opendir($uncpath);
echo "<pre>\n";
var_dump($dh, error_get_last());
echo "\n</pre>";
Try the file: URI scheme:
file://server/dir
file:///Z:/dir
The begin is always file://. The next path segment is the server. If it’s on your local machine, leave it blank (see second example). See also File URIs in Windows.
Yes, I know this is an old post, but I still found it, and if anyone else does...
On Windows, with newer servers, verify the SMB is installed and enabled on the target machine.

Categories