I'm using PHP to retrieve the city of an IP using the GeoLite2 Free Downloadable Database.
The code I'm using is the following one:
function getGeoLocationFromIp()
{
include_once('Db/Reader.php');
include_once('Db/Reader/Decoder.php');
include_once('Db/Reader/InvalidDatabaseException.php');
include_once('Db/Reader/Metadata.php');
include_once('Db/Reader/Util.php');
//use MaxMind\Db\Reader;
$reader = new Reader('/sys/class/GeoLite2-City.mmdb');
$ipData = $reader->get('xx.xx.xx.xx');
return $ipData;
}
The Db folder is in the following path: "www/Admin%20Panel/Db" and so the city database "www/Admin%20Panel/sys/class/GeoLite2-City.mmdb".
As you can see I commented use MaxMind\Db\Reader; because it crashes my web page.
I always had a problem with Classes and for this reason I never used them but now I have to and, as feared, they don't work.
I'm working directly online so I'm not even able to see the error log.. :(
Any idea on how I can make that Class work?
Thank you all :)
Related
I state that I'm not familiar with Prestashop and I'm using version 1.7.6.
I'm trying to understand how I could use the import function from csv file without using of user interface.
I tried to look for documentation on a possible web api but I found nothing.
What I'd like to accomplish is the following scenario:
I have two web applications on the same server
/my_webapp
/my_prestashop
By "my_webapp" I receive a csv file, process it and produce a new csv file.
Now continuing running the process in "my_webapp", I would like to instantiate the ambient of the prestashop application to invoke the import csv function by passing it the new file just created.
Searching the web I found some sample code but, trying to use and adapt it, I am not making it work.
For example, on “my_webapp” folder I just create a “myimport.php” file and call it with two GET parameters.
The following is the call:
localhost/my_webapp/myimport.php?csv=prod.csv&limit=5
note: the file “prod.csv” is on
"path to admin folder"/import
Content of “myimport.php” file:
<?php
$rootPrestashop = '/var/www/html/my_prestashop”;
define('_PS_ADMIN_DIR_', $rootPrestashop.'/admin_shop'); //not sure if this instruction is needed
$pathConfig = $rootPrestashop.'/config/config.inc.php';
$initConfig = $rootPrestashop.'/init.php';
require_once($pathConfig);
require_once($initConfig); //this line throw an error and then I can't test the others!
$importCtrl = new AdminImportControllerCore();
$crossSteps = array();
$limit = $_GET["limit"];
$importCtrl->productImport(false, $limit, $crossSteps, true, 0);
This is what I’m trying to do, but I failed to initialize the environment.
Maybe I’m on the wrong way and there’s a better way.
I ask if anyone can help me understand if I can carry out this process and what would be the correct way.Thanks in advance
if (!defined('_PS_ADMIN_DIR_')) {
define('_PS_ADMIN_DIR_', __DIR__);
}
include _PS_ADMIN_DIR_.'/../config/config.inc.php';
if (!Context::getContext()->employee->isLoggedBack()) {
Tools::redirectAdmin(Context::getContext()->link->getAdminLink('AdminLogin'));
}
Im trying to connect to the FedEx PHP plugin, Ive successfully ran the plugin with my local Server. But when I try to run it on my CakePhp project I get the next error:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://my-subdomain.mydomain.com/controller/wsdl' : Entity 'raquo' not defined
Using the url I can actually enter the wdsl page and see the file in XML file. I got a function and view which return this. This is that functions code:
public function wsdl() {
$this->layout = false;
$this->RequestHandler->respondAs('xml');
}
I can enter the url and see the correct display of the XML. Then when I try using the wsdl on my function which is in the same class I get the error above. This is the code I use to call the SOAP class:
//The WSDL is not included with the sample code.
//Please include and reference in $path_to_wsdl variable.
$path_to_wsdl = "http://apibebe2go.bebe2go.com/home/wsdl";
ini_set("soap.wsdl_cache_enabled", "0");
$client = new SoapClient($path_to_wsdl, array('trace' => 1));
I get and internal error from the CakePhp debug and the error above. Any ideas what I could try to make this work? If you guys need any more code Ill be happy to help :D
Ok I solved the problem another way. Not sure why the /wdsl file was not working when called via function to view, BUT I added the .wdsl file to the WebRoot file path I had and called the url from there. Now it works like it should. If you need further explanation on how I achieved this, feel free to ask here :D
Cheers! :P
I'm trying to learn REST, and thought it might be good to start with a PHP REST client such as Httpful. I just can't seem to get it to work. I downloaded the httpful.phar file and placed it in my working directory. Then created a simple php file with the following contents from an example on the their site:
<?php
// Point to where you downloaded the phar
include('httpful.phar');
$uri = "https://www.googleapis.com/freebase/v1/mqlread?query=%7B%22type%22:%22/music/artist%22%2C%22name%22:%22The%20Dead%20Weather%22%2C%22album%22:%5B%5D%7D";
$response = Request::get($uri)->send();
echo 'The Dead Weather has ' . count($response->body->result->album) . " albums.\n";
?>
I've tried multiple examples on the site, but only get a blank page when I load it in my browser.
Thanks for any help you can give!
This library uses Namespaces. Either use a complete classname or use the class
With a complete Classname:
\Httpful\Request::get($uri)->send();
With a use:
use Httpful\Request;
Request::get($uri)->send();
The sample code sadly is very incomplete on the website, but you can get the hint from sample below topic "INSTALL OPTION 1: PHAR" or from the actual source code inside the phar.
http://phphttpclient.com/
I have to establish connection with Samba server from my php script in order to download some files into my local server.
Actually its first time I have heard of something like Samba so I Tried to look for a opensource code that I could make use of.
Here it is what I have found: First class - smbclient.php and I tried code posted on the page:
<?php
require_once ('smbclient.php');
$smbc = new smbclient ('//10.0.1.1/example', 'exampleuser', 'examplepassword');
if (!$smbc->get ('path/to/desired/file.txt', '/tmp/localfile.txt'))
{
print "Failed to retrieve file:\n";
print join ("\n", $smbc->get_last_stdout());
}
else
{
print "Transferred file successfully.";
}
?>
Adjusting it into my needs ( server, user, password), all i got is
Failed to retrieve file:
Fatal error: Call to undefined method smbclient::get_last_stdout()
Then I found out about smbwebclient.php project which looks awesome and can be found here.
And this class looks good but the problem is that I have no idea how to use it. Can anyone post it example connection or link to tutorial?
To get files from a samba server, you can try to use a smb wrapper, like the one here but changing the deprecated splits with explodes. Then you can include your php file using this code:
include_once('smb.php');
include( 'smb://user:password#server/folder/file.php');
Reviving old thread but I think I found the solution, the code must have changed since the pot was made on the blog:
print join ("\n", $smbc->get_last_stdout());
should now be
print join ("\n", $smbc->get_last_cmd_stdout());
My problem is I need to fetch FOOBAR2000's title because that including information of playing file, so I create a execute file via Win32 API(GetWindowText(), EnumWindows()) and it's working good.
TCHAR SearchText[MAX_LOADSTRING] = _T("foobar2000");
BOOL CALLBACK WorkerProc(HWND hwnd, LPARAM lParam)
{
TCHAR buffer[MAX_TITLESTRING];
GetWindowText(hwnd, buffer, MAX_TITLESTRING);
if(_tcsstr(buffer, SearchText))
{
// find it output something
}
return TRUE;
}
EnumWindows(WorkerProc, NULL);
Output would look like "album artis title .... [foobar2000 v1.1.5]"
I created a php file like test.php, and use exec() to execute it.
exec("foobar.exe");
then in console(cmd) I use command to execute it
php test.php
It's working good too, same output like before.
Now I use browser(firefox) to call this php file(test.php), strange things happened.
The output only foobar2000 v1.1.5, others information gone ...
I think maybe is exec() problem? priority or some limitation, so I use C# to create a COM Object and register it, and rewrite php code
$mydll = new COM("FOOBAR_COMObject.FOOBAR_Class");
echo $mydll->GetFooBarTitle();
still same result, command line OK, but browser Fail.
My question is
Why have 2 different output between command line and browser. I can't figure it out.
How can I get correct output via browser.
or there is a easy way to fetch FOOBAR2000's title?
Does anyone have experience on this problem?
== 2012/11/28 edited ==
follow Enno's opinion, I modify http_control plug-in to add filename info, original json info is "track title".
modify as following
state.cpp line 380 add 1 line
+pb_helper1 = pfc::string_filename(pb_item_ptr->get_path());
pb_helper1x = xml_friendly_string(pb_helper1);
# 1: when firefox opens the php and it gets executed, it the context depends on the user which runs the php-container (apache), this is quite different from the commandline call which gets executed in your context
# 2 and 3: there seems to be more than one way for getting the title: use the foobar-sdk and create a module which simply reads the current title per api, then write your result in an static-html-document inside your http-root-folder OR use the http-client inside the sdk, with it, you do not need a wabserver, even better use a already implemented module: for instance foo_upnp or foo-httpcontrol
Good luck!
If your webserver runs as a service, in windows you need to enable "allow desktop interaction" for the service. Your php script runs as a child of the webserver process when requested via browser.