Call to undefined function geoip - php

I installed PHP 5.4 and GeoIP but I can't get the GeoIP to work.
the error is:
Fatal error: Call to undefined function geoip_country_code_by_name() in /var/www/html/geoip/test.php on line 7
This is the script:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
//$gi = geoip_open( "GeoIP.dat",GEOIP_STANDARD);
$country = geoip_country_code_by_name('www.example.com');
if ($country) {
echo 'This host is located in: ' . $country;
}
?>
I installed PEAR/PECL still nothing.
is there a log error for geoip or something that can help with is issue?
also I installed GeoIP with PHP 5.3 and it works fine. the problem is with PHP 5.4
Thanks.

There seems to be a mis-configuration or you are giving the function name wrong. To check that it's successfully installed/active;
if (function_exists("Function_Name_Here")) {
echo "Function Does Exist";
} else {
echo "Function Does Not Exist";
}
If this function "does not exist" then re-trace through your installation steps of consult the official manual of this extension for exact installation instructions.

Related

Uncaught Error: Class 'WindowsAzure\Common\ServicesBuilder' not found- MS Azure | PHP

I have created the composer.json file in my root folder where my index.php file is presents, with the following code in it:
{
"require": {
"microsoft/windowsazure": "^0.5"
}
}
and on downloading composer.phar, I have installed it using:
php composer.phar install
I'm trying to create a table and add entities to it in php. I use the command
use WindowsAzure\Common\ServicesBuilder;
$connectionString = 'DefaultEndpointsProtocol=https;AccountName=******;AccountKey=***/***************************/******************/**********************************==';
$tableRestProxy = ServicesBuilder::getInstance()->createTableService($connectionString);
try {
// Create table.
$tableRestProxy->createTable("mytable");
}
catch(ServiceException $e){
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
When I run this on local host on my Ubuntu, I get an error saying-
Uncaught Error: Class 'WindowsAzure\Common\ServicesBuilder' not found in /home/my_folder/php-docs-hello-world-master/index.php:30
If I add
require_once 'vendor/autoload.php';
before defining my $connectionString, then my error changes to:
/index.php - Uncaught RuntimeException: Error creating resource: [message] fopen(https://eyesav.table.core.windows.net/Tables): failed to open stream: Unable to find the socket transport "http" - did you forget to enable it when you configured PHP?
Can someone help me figure out this issue, if it is with the installation of my composer, or my connectionString, or something else?
Thanks in advance :)
Can someone help me figure out this issue, if it is with the installation of my composer, or my connectionString, or something else?
If I use the code you mentioned, I also could reproduce the issue you mentioned.
Please have a try to use following code to create the table client. It works for me.
use MicrosoftAzure\Storage\Table\TableRestProxy;
use MicrosoftAzure\Storage\Common\ServiceException;
$tableClient = TableRestProxy::createTableService($connectionString);
The following is the demo code from azure official document.
<?php
require_once "vendor/autoload.php";
use MicrosoftAzure\Storage\Table\TableRestProxy;
use MicrosoftAzure\Storage\Common\ServiceException;
$connectionString = 'DefaultEndpointsProtocol=https;AccountName=xxxx;AccountKey=xxxxxxx;';
$tableClient = TableRestProxy::createTableService($connectionString);
try {
$tableClient->createTable("mytable");
}
catch(ServiceException $e){
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}

PHP can't connect to SQL Server

I have been thrown into the world of PHP, and I'm having a bit of an issue connecting to my SQL server. I'm using the following code to try to connect. When it hits the SQLsrv_connect command, it just seems to stop processing. No error, it just stops loading.
function testConnection()
{
$returnable = "TEST";
echo 'Current PHP version: ' . phpversion();
$connectionInfo = array("Database"=>"MyDatabase", "UID"=>"MyLogin", "PWD"=>"MyPassword");
$conn = sqlsrv_connect("MyServer",$connectionInfo);
if ($conn) {
echo "Connection Established.<br />";
} else {
echo "Something went wrong while connecting to MSSQL.<br />";
}
return $returnable;
}
Any idea on what I might be missing? I tried some very old syntax for version 5, and I got the same issue. I am trying to connect to sql server 2008.
Thanks
First, check if you have installed the sql_srv extension for PHP.
Probably this extension is not installed/loaded by you php.ini file.
For Windows
Download proper driver from SQL Driver for MSSQL extract and copy into you php installation directory. Then edit php.ini file and add in extensions path your extension. (For 99% you should copy NTS sql_srv version) also don't forget add sql_srv_pdo extension.
For Ubuntu/Linux
You can try install sql_srv and pdo_sql_srv by pecl (if is installed)
pecl install sqlsrv pdo_sqlsrv.

SSH in xampp install php

I need to use a connection SSH and PHP, I have version PHP 5.6.8 ,
intall OpenSSL-Win32;
In php.ini :
extension=libssh2.dll ;librerias ssl2
extension=php_ssh2.dll
The libraries are in the folder php---->ext.
With the next program my result is:
Fatal error: Call to undefined function ssh2_connect() in
C:\xampp\htdocs\conexion\conexion_ssh.php on line 2
<?php
$connection = ssh2_connect('X.X.X.X', XX);
if (ssh2_auth_password($connection, 'root', 'XXXXXXXX')) {
echo "Authentication Successful!\n";
} else {
die('Authentication Failed...');
}
?>
Do you know the problem? I think is the configuration the system variable PATH but I don't Know the process.
Thanks for you help me!

pecl_http extension not working

I installed pecl_http extension in windows and I ran the following code:
<?php
$r = new HttpRequest('http://example.com/feed.rss', HttpRequest::METH_GET);
$r->setOptions(array('lastmodified' => filemtime('local.rss')));
$r->addQueryData(array('category' => 3));
try {
$r->send();
if ($r->getResponseCode() == 200) {
file_put_contents('local.rss', $r->getResponseBody());
}
} catch (HttpException $ex) {
echo $ex;
}
?>
I get error as below:
Fatal error: Class 'HttpRequest' not found in C:\xampp\htdocs\web_services\pecl_http.php on line 3
This is how I installed pecl_http:
downloaded and added following lines to php.ini (thread safe vc9)
extension=php_raphf.dll
extension=php_propro.dll
extension=php_http.dll
This is what I get when I run phpinfo() function:
I am using php 5.4.22 (xampp) on windows 8.
Why am I getting this class not found error when I have the pecl extension enabled?
Well I figured out what was wrong. I installed http version 2 extension which is a complete renovation of version 1. Instead of HttpRequest class, we have http \ Client () class. I got this information from one of the comments on http://us2.php.net/manual/en/http.install.php.
The documentation for http 2 is at http://devel-m6w6.rhcloud.com/mdref/http/. The documentation lacks example though.

why wkhtmltopdf doesn't work with php

I ran the codes:
error_reporting(E_ALL);
ini_set( 'display_errors','1');
$d = 'usr/bin/wkhtmltopdf /www/11_07_13/task1/ml.html hd.pdf';
//also used: $d = 'xvfb-run -a wkhtmltopdf ml.html hd.pdf';
//$d = 'xvfb-run -a usr/bin/wkhtmltopdf ml.html hd.pdf';
if (exec($d)) {
echo "success";
}
else{
echo "error";
}
and everytime it shows error.
At first I installed wkhtmltopdf via terminal, dinn't work. Then I downloaded the file: wkhtmltopdf-0.11.0_rc1-static-i386.tar.bz2' from the code.google... site, unzipped and placed it in my www/test folder to use with php; with no luck.
but the command 'wkhtmltopdf test.html test.pdf' from terminal woks just fine.
Then where is the problem???
Can anyone please help me out???
p.s. I use ubuntu 12.04. php 5.4.7
The error message from exec call shows: Array ( [0] => /usr/bin/wkhtmltopdf: /opt/lampp/lib/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib/i386-linux-gnu/libstdc++.so.6) )

Categories