I am using an opensource PHP library to communicate to a Onvif capable IP camera.
There was one function missing in the library, GetSnapshotUri which returns an URL where one can get a snapshot of the main stream.
Here is the source: http://pastebin.com/ekJa4D2h
Here is main page:
<?php
require 'class.ponvif.php';
$onvif = new Ponvif();
$onvif->setUsername('admin');
$onvif->setPassword('admin');
$onvif->setIPAddress('192.168.1.100');
try
{
$onvif->initialize();
$sources = $onvif->getSources();
$profileToken = $sources[0][0]['profiletoken'];
$uri = $onvif->media_GetSnapshotUri($profileToken);
}
catch(Exception $e)
{
print $e;
}
?>
For some reason, the isFault function is true and i have no clue why.
The XML is valid, i checked it with Wireshark.
Does anybody have another camera to this if this works?
I have tried with 2 different camera's, Grandstream and Hikvision.
Also with ONVIF Device Manager v2.2.250 everything works as it should.
I know this is a long shot, but i have absolutely no clue.
fix is here: http://pastebin.com/ryqxFjdR
mediaurl instead of getsnapshoturl in the function.
Related
I want to put my fortnite stats on my website HTML/CSS. I find this.
But I don't know php very good, so I need your help. Must I delete this: 'your_api_key' and put : your_api_key without the ' ' ?
And lines like this:
$this->auth = new Fortnite_Auth($this);
$this->challenges = new Fortnite_Challenges($this);
$this->leaderboard = new Fortnite_Leaderboard($this);
$this->items = new Fortnite_Items($this);
$this->news = new Fortnite_News($this);
$this->patchnotes = new Fortnite_PatchNotes($this);
$this->pve = new Fortnite_PVE($this);
$this->status = new Fortnite_Status($this);
$this->weapons = new Fortnite_Weapons($this);
$this->user = new Fortnite_User($this)
Must I modify something?
(here are some informations:
-user_id: 501b9f2dfda34249a2749467513172bf
-username: NoMaD_DEEPonion
-platform: pc
-windows: season 5
)
For all this code, I used xammp server (I hope it's good)
Thank you for your help
You should always quote '' your key/strings. So it would look like:
$api->setKey('123qwerty456');
$api->user->id('NoMaD_DEEPonion');
Please read their documentation. You're supposed to get an API key from them to get started. And you don't have to edit Client.php. You're supposed to include the files instead. Try including Autoloader.php, since it requires the necessary files.
XAMPP is alright for development, but not suitable for production/public. Good luck!
What #sykez wrote.
I personally use https://fortniteapi.com/ to get the data. They also have a sweet POSTMAN page with different requests https://documenter.getpostman.com/view/4499368/RWEjoGqD
At last. I am not really sure that this will be a good project to start learning PHP from. I really suggest that you get to understand the basics of PHP first before you jump into API calls, processing arrays and more.
I am working on a web project that involves connecting to SharePoint Online via PHP and accessing the files stored on it. But I am extremely new to all this, and have hit a wall.
I have the URL of the file I'm trying to access
Using the phpSPO library, I am authenticated and connected to SharePoint.
The question is: how do I actually access the URL? If I follow the link directly, it redirects me to the login page for SharePoint. But we want the login to happen "behind the scenes" - and apparently the authentication step doesn't quite do that.
The company we are working with told us that we would need to request an anonymous link for the URL by calling a function. Problem is, the function they told us to use works in ASPX, but doesn't appear to be available in PHP.
This is the code they pointed us to:
Uri siteUri = new Uri(siteUrl);
Web web = context.Web;
SecureString passWord = new Secure String();
foreach (char c in "password".ToCharArray())
passWord.AppendChar(c);
context.Credentials = new SharePointOnlineCredentials("userid", passWord);
WebDocs.Parameter1 = "123456"
WebDocs.Parameter2 = "Test"
context.Web.CreateAnonymousLinkForDocument(WebDocs.Parameter1, WebDocs.Parameter2, ExternalSharingDocumentOption.View);
But how can I translate that into PHP? Can I even do that?
And if not, is there another way that I can access the file to display it to my user?
// this says the function CreateAnonymousLinkForDocument doesn't exist
function getLink(ClientContext $ctx) {
$anonymousLink = $ctx->getWeb()->CreateAnonymousLinkForDocument();
$ctx->load($anonymousLink);
$ctx->executeQuery();
}
Well, after hours and hours of searching the Internet....
The answer was right in front of my nose.
Started browsing through the examples/SharePoint/file_examples.php that came with the phpSPO library, and discovered 2 functions (either one works).
One is called downloadFile, and the other is downloadFileAsStream.
function downloadFile(ClientRuntimeContext $ctx, $fileUrl, $targetFilePath){
$fileContent =
Office365\PHP\Client\SharePoint\File::openBinary($ctx,$fileUrl);
file_put_contents($targetFilePath, $fileContent);
print "File {$fileUrl} has been downloaded successfully\r\n";
}
function downloadFileAsStream(ClientRuntimeContext $ctx, $fileUrl,
$targetFilePath) {
$fileUrl = rawurlencode($fileUrl);
$fp = fopen($targetFilePath, 'w+');
$url = $ctx->getServiceRootUrl() . "web/getfilebyserverrelativeurl('$fileUrl')/\$value";
$options = new \Office365\PHP\Client\Runtime\Utilities\RequestOptions($url);
$options->StreamHandle = $fp;
$ctx->executeQueryDirect($options);
fclose($fp);
print "File {$fileUrl} has been downloaded successfully\r\n";
}
Since I was trying to download a PDF, I just set these functions to create a PDF on our own server.... and it works beautifully!!!!!
I want to get the country name of people who gets in my site, unfortunately I am using a godaddy's hosting account and I cannot use the $_server['geoip_country_name'], but I could install
Net_Geo (1.0.5)
Net_GeoIP (1.0.0)
Services_GeoNames (1.0.0)
These are pearl modules and services_geonames should help me to get the names, checking the docs I found this:
Looking up the country name
<?php
require_once "Net/GeoIP.php";
$geoip = Net_GeoIP::getInstance("/path/to/geoipdb.dat");
try {
echo $geoip->lookupCountryName($_SERVER['REMOTE_ADDR']);
} catch (Exception $e) {
// Handle exception
}
?>
But I dont really know how to include the .dat library using this hosting, any idea how to use this service? or use another one?
Thanks
Just upload the .dat file to one of your folders and include it...
Download # http://dev.maxmind.com/geoip/legacy/geolite/#Downloads
ie; upload to abc/
<?php
require_once "Net/GeoIP.php";
$geoip = Net_GeoIP::getInstance("abc/geoipdb.dat");
try {
echo $geoip->lookupCountryName($_SERVER['REMOTE_ADDR']);
} catch (Exception $e) {
// Handle exception
}
?>
Also you can get https://github.com/maxmind/geoip-api-php for use with the maxmind DB
This is a PHP script I use to get the referring website for each new visitor to my site.
If the visitor came from Google, I get the keyword they used to find the site.
This data is stored in the session then included along with the data from the contact form when an enquiry is sent. This allows clients with little knowledge of analytics to track converting keywords.
I need to convert this PHP to work on a site that uses .aspx pages. After researching asp.net for several hours, I feel like I still don't have a clue where to start!
<code>
<?php
session_start(); // start up your PHP session!
if (empty($_SESSION['google'])) {
// if session is empty, take the referer
$thereferer = strtolower($_SERVER['HTTP_REFERER']);
// see if it comes from google
if (strpos($thereferer,"google")) {
// delete all before q=
$a = substr($thereferer, strpos($thereferer,"q="));
// delete q=
$a = substr($a,2);
// delete all FROM the next & onwards
if (strpos($a,"&")) {
$a = substr($a, 0,strpos($a,"&"));
}
// we have the key phrase
$_SESSION['google'] = urldecode($a);
$_SESSION['referer'] = 'Google';
}
}
if (empty($_SESSION['referer'])) {
$_SESSION['referer'] = $_SERVER['HTTP_REFERER'];
}
?>
</code>
I'd really appreciate a point in the right direction with this.
Thanks.
You need to read up on the HttpRequest and HttpResponse classes. More specifically, the Request.ServerVariables collection, the Request.Cookies object, and the Response.Cookies object.
I had an idea that would require me be able to send and receive messages via the standard messenger protocols such as msn, icq, aim, skype, etc...
I am currently only familiar with PHP and Python and would thus enjoy a library which I can access from said languages. I have found phurple (http://sourceforge.net/projects/phurple/) for php and python-purple (http://developer.pidgin.im/wiki/PythonHowTo) which don't seem to be to up to date. What would you guys suggest to do? My goal will be to write a webapplication in a distant way like meebo.com
The answer should include a tutorial or example implementation and a decent documentations.. the pidgin.im doesn't really have a useful tutorial..
alternativly you can also just tell me different kinds of implementations, so that I would build my own class out of an existing icq, aim, msn etc implementation.
An example of how to connect to an account (login) and then sending one message would be the ultimate help!
Come one guys :)
Here is how to connect to the Pidgin DBus server.
#!/usr/bin/env python
import dbus
bus = dbus.SessionBus()
if "im.pidgin.purple.PurpleService" in bus.list_names():
purple = bus.get_object("im.pidgin.purple.PurpleService",
"/im/pidgin/purple/PurpleObject",
"im.pidgin.purple.PurpleInterface")
print "Connected to the pidgin DBus."
for conv in purple.PurpleGetIms():
purple.PurpleConvImSend(purple.PurpleConvIm(conv), "Ignore this message.")
else:
print "Could not find piding DBus service, make sure Pidgin is running."
Don't know if you have seen this, but here is the official python DBus tutorial: link.
EDIT: Re-adding link to the pidgin dev wiki. It teaches you everything I posted above,
just scroll further down the page. http://developer.pidgin.im/wiki/PythonHowTo
A good bet would be to go through the DBus interface: Pidgin (purple) fully supports it and the DBus interface library for Python is quite stable.
If you decompress the file from phurple you get some example like this:
<?php
if(!extension_loaded('phurple')) {
dl('phurple.' . PHP_SHLIB_SUFFIX);
}
class CustomPhurpleClient extends PhurpleClient {
private $someVar;
protected function initInternal() {
$this->someVar = "Hello World";
}
protected function writeIM($conversation, $buddy, $message, $flags, $time) {
if(PhurpleClient::MESSAGE_RECV == $flags) {
printf( "(%s) %s %s: %s\n",
$conversation->getName() ? $conversation->getName() : $buddy->getName(),
date("H:i:s", $time),
is_object($buddy) ? $buddy->getAlias() : $buddy,
$message
);
}
}
protected function onSignedOn($connection) {
print $this->justForFun($this->someVar);
}
public function justForFun($param) {
return "just for fun, the param is: $param";
}
}
// end Class CustomPhurpleClient
// Example Code Below:
try {
$user_dir = "/tmp/phphurple-test";
if(!file_exists($user_dir) || !is_dir($user_dir)) {
mkdir($user_dir);
}
PhurpleClient::setUserDir($user_dir);
PhurpleClient::setDebug(true);
PhurpleClient::setUiId("TestUI");
$client = CustomPhurpleClient::getInstance();
$client->addAccount("msn://nick#hotmail.com:password#messenger.hotmail.com:1863");
$client->connect();
$client->runLoop();
} catch (Exception $e) {
echo "[Phurple]: " . $e->getMessage() . "\n";
die();
}
?>
I use WebIcqLite: ICQ messages sender for the ICQ protocol. It works and the class is easy to understand. I don't know about other protocols, though. What's wrong with the Phurple library?