How do i check if php server allows connecting via curl to external sites before buying hosting package (or registering on free host)? I noticed that in some hosting reviews users were complaining that servers that have curl enabled often don't allow external connections...
I'd like to check this before purchasing/registering. Maybe there's some string in phpinfo which i can check (hosts sometimes link to their phpinfo so i don't need to be registered and create it myself) or something else i can do to check this without having account?
If I have to register first... maybe there are some phpinfo-like scripts with more extensive informations that i could upload and run to quickly test host?
Create a file like this:
<?php
phpinfo();
?>
or
<?php
echo "<pre>";
var_dump(curl_version());
?>
That will tell you instantly.
Also, most free hosts do not offer Curl by default, due to abuse by spammers.
You'll definitely need to buy an account before testing the server's capacities.
But some hosts allow you to test their site with a monthly contract or a XX days money back guarantee. From the top of my head, Host gator is such host.
Then when you have that account, try a small script like this (check the path to curl with your host helpdesk or documentation):
<?php
$var = echo shell_exec("/usr/bin/curl -L http://www.google.com");
?>
Related
I've created a module for my client's project that should send a file via FTPS onto a web-service. The web-service allows connection from some IP addresses only.
It works on my localhost, but some FTP-commands don't work on the client's live site.
For example, primarily I connect with ftp_ssl_connect. It works on the client's site.
Then, I log in with ftp_login. It also works on the client's site.
Then, I move to the passive mode with ftp_pasv. It also works on the live site.
But when I'm trying to get the files list with ftp_nlist command, it works on from my localhost but refuses to execute on the client's site.
Also, when I send a file with command ftp_put, it works on my localhost but refuses to work from the client's project.
$config = yrv_eboks_get_config_data();
$conn = ftp_ssl_connect($config->ftp_host, 21, 15);
if (ftp_login($conn, $config->ftp_login, $config->ftp_password)) {
if (ftp_pasv($conn, true)) {
$files = ftp_nlist($conn, ".");
var_dump($files);
}
} else {
// "Could not login via login via FTPS"
};
I don't know where is the problem and how to solve it.
Could you advise me, where can be the problem and what to do?
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
write this at the top of the file and access the php file your browser will display the error. are you sure these functions are enabled on your hosting? because shared server disable lots of function to prevent abuse for example source, symlink, ftp_put etc.
You can check which function is disabled by creating a phpfile using below code
<?php
phpinfo();
?>
save the above code as anyname.php then access it and you will see php information there. press ctrl+f (search) button and write disable_functions and there you will see all the disabled functions or create a file with the below code and access it from browser ( it may not work if your provider blocked ini_get function too)
<?php echo "Disabled functions: ".ini_get('disable_functions')."\n"; ?>
if your function is disabled you can enable them by creating php.ini file in your directory or request your hosting provider to enable them.
to enable function: create php.ini with following code
disable_functions = ""
however it may not works if your hosting environment is use default php.ini with priority so better contact with provider and request them to enable.
Can I permit RDP based connections from a website using PHP/JS/etc? I've read that RDP session files can be placed on the web server but would prefer to implement it via code. I am looking for the best way to offer a centralized management of windows machines and allow direct RDP connections.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa383019%28v=vs.85%29.aspx
This looks like it could potentially work, although it requires IIS as the web-server and requires a role to be installed on all remote machines. If possible, I would like to find a solution permitting this to work under a Nix based web-server and without any need for modifications on the remote servers.
This problem was resolved by creating an .rdp session file with PHP. Not to cleanest approach as a embedded solution would be better, but is the most viable I have found.
<?
$file = 'screen mode id:i:2
desktopwidth:i:1436
desktopheight:i:925
session bpp:i:16
auto connect:i:1
full address:s:<SERVERIP>:<SERVERPORT>
compression:i:1
keyboardhook:i:2
audiomode:i:2
redirectdrives:i:0
redirectprinters:i:0
redirectcomports:i:0
redirectsmartcards:i:0
displayconnectionbar:i:1
alternate shell:s:
shell working directory:s:
disable wallpaper:i:1
disable full window drag:i:1
disable menu anims:i:1
disable themes:i:1
bitmapcachepersistenable:i:1
winposstr:s:0,3,0,0,800,600
redirectclipboard:i:1
redirectposdevices:i:0
drivestoredirect:s:
autoreconnection enabled:i:1
authentication level:i:0
prompt for credentials:i:0
negotiate security layer:i:1
remoteapplicationmode:i:0
allow desktop composition:i:0
allow font smoothing:i:0
disable cursor setting:i:0
gatewayhostname:s:
gatewayusagemethod:i:0
gatewaycredentialssource:i:4
gatewayprofileusagemethod:i:0';
header("Content-Disposition: attachment; filename=filename.rdp");
header("Content-Type: application/rdp");
print $file;
exit();
?>
When I run the following code on one of my websites:
<?php
$thing = file_get_contents("http://mywebsite.com:8080/Public");
echo($thing);
?>
It returns expected result, the contents of http://mywebsite.com:8080/Public
But when I run it on my other website (hosted on by a different company), it does not display anything. No errors and not the contents of http://mywebsite:8080/Public. However, if I run the following code:
<?php
$thing = file_get_contents("http://somerandomwebsite.com");
echo($thing);
?>
It returns the contents of somerandomwebsite.com. Is there a reason why it works on one of the websites and not the other? Why can it only fetch the contents of the file if the port is 80?
Check with your hosting provider if it allows PHP to make external requests. Some shared hosting providers disable that.
file_get_contents fails because it cannot retrieve the content at hand. Most likely, a simplistic firewall is blocking all traffic to non-80 ports. You'll have to use port 80 to avoid these simplistic firewalls.
The failure to download the resource makes php emit a warning. Most likely, warnings are not displayed on the production server. Check the server's log and the display_errors and error_reporting configurations.
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.
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.