I can't figure out what exactly to use for interaction between my site and the Telegram service (first of all - how to get the authentication process done using PHP and other stuff like chat among users).
On this page: https://core.telegram.org/api I haven't got an idea how to use those functions in PHP.
According to this page: https://telegram.org/apps
I have two choices:
1) The CLI-interface (unofficial, by the way): https://github.com/vysheng/tg
and it doesn't have an autentification function among others. In order to authenticate yourself, you need to run:
bin/telegram-cli -k tg-server.pub
and inside of the application you have to enter your cell phone and the secret code sent by SMS - after that you're authorized. Then you install https://github.com/zyberspace/php-telegram-cli-client and run telegram-cli as a daemon:
./bin/telegram-cli -dWS /tmp/tg.sck -k tg-server.pub &
Does it mean that I have to create tg-server.pub manually using PHP for each user which is trying to login?
2) Webogram: https://github.com/zhukov/webogram - but it's written on JavaScript and has very complicated code.
Dear Stackoverflow gurus, maybe you're more attentive than I am and could help me to recognize the right solution (or example, I don't know, the PHP snippet or anything else) for the user's chat based on the Telegram and PHP?
I would greatly appreciate it!
Thank you!
I have posted a step by step guide on getting your AuthKey (VB.net) here
The main challenge with Telegram API is the documentation... but if you can work through the first part - getting an AuthKey then i believe the rest should fall in place ... with some more effort.
Working through some GitHub src might be time consuming, it might be best to get a handle on the documentation and then work your way to building your own code for TelegramAPI from scratch
Most likely, PHP wrapper for Telegram API doesn't exist. I'd wager it's because communicating with Telegram servers from your server-side PHP code defeats both of the core features of Telegram: speed and security.
no speed - a message has to hop through one additional loop (your server) before it reaches the recipient.
no security - browser page will communicate with your server via AJAX or forms, I assume. This means sending data as plain text (unless you're on https), open to the whole world to see (if you were to sit on a public wifi, or something like that).
You can implement the Telegram API, it's a bit involved, but doable. But it's totally pointless, in my opinion.
As an alternative, just embed the webogram in an <iframe> or something :)
Now, you can use MadelineProto https://github.com/danog/MadelineProto - enought powerful PHP client for MTProto Telegram!
Related
I'm trying to make an app that automatically prints a PDF after it has been generated for the client. (by his request) I got a cloud printer up and running which works perfectly fine if I try to use it with something like chrome.
All libaries for PHP are extremely outdated (up to 4 years old) and most of them are completely broken or provide little to no documentation on how to use them, and trying to use google's own documentation is even more of a nightmare
The best I could come up with was using this libary: yasirsiddiqui/php-google-cloud-print, mostly because it was the only one I could actually figure out how to use it.
However when I use this to submit a print job the owner of the account (me) gets a warning email that someone suspicious is trying to log into their account and it has been blocked.
Does anyone know if there is a (working) library to do this with, or if there is a command line alternative (preferred) that I could use system() or exec() with?
Note: I have 0% knowledge of python, and using JavaScript to submit these jobs is NOT an option because end users are not allowed to alter the document.
Update [2015/09/08]: For some reason Google doesn't allow printing via some accounts even when using OAuth2, a quick hack to fix this was by simply creating an entirely new account and printing with that.
I have updated code to use Google OAuth2 and now there will not be any issues related to account blocked or security risk etc. Here is url of updated code
https://github.com/yasirsiddiqui/php-google-cloud-print
I've never heard of Google Cloud printing but it appears to just be a simple REST API, in which case you do not need a library to interact with it, just use something like CURL. Here is a page which lets you test out the various interfaces they offer:
https://www.google.com/cloudprint/simulate.html
A dry parameter list is available here for submitting jobs:
https://developers.google.com/cloud-print/docs/appInterfaces#submit
I would just use CURL to post my requests and not worry about over engineering some huge class especially when you don't need every available option in the API. You should look at the Python examples- I know that you do not have much experience with Python but the HTTP headers you set to login, etc, will be the same as in PHP:
login.putheader('content-type', 'application/x-www-form-urlencoded')
Is the same as:
$request_headers[] = 'content-type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);`
I did find an API here, but it is behind a paywall so I cannot attest to it's quality- if you're doing this for a client though it may be worth the money and effort saved to check it out:
http://www.phpgang.com/how-to-configure-google-cloud-api-in-php_288.html
I am a PHP developer and the title basically says it all. However I was hoping on some more in-depth information as I am starting to get confused about how the flow for the project I work on should go.
For an (web) application I need to implement a feature like Facebook does it with notifying users about replies/comments and instantly showing these.
I figured I could use long-polling with ajax requests but this does not seem to be a nice solution as the notifications never really are instant and it is resource heavy.
So I should use some form of sockets if I understand correctly, and Node.Js would be a good choice. So based on the last assumption I now get confused about the work flow.
I thought about two possible solutions:
1) It seems to me, that if I would use Node.Js I could skip using PHP at all and base the application on Node.js only.
2) Or I could use PHP as a base and only use Node.js for notifying users and instantly showing messages but saving the data using PHP and Mysql.
These two possibilities confuse me and I can't make up my mind about what would be the "best" and cleanest way.
I do not have much experience in Node.js, played with it for a while. But managing and saving data seems to be hard in Node.js so that is why I came up with option 2.
I know Facebook is build on PHP so I am assuming that they save the data via PHP and notify / instantly show replies and comments via Node.
Could someone help me out on this?
Thanks in advance!
EDIT:
I just noticed, Stackoverflow does something similar. I get a notification in the upper left, and below my question a box with "new answer to this question". I am really interested in the technologie(s) used.
Well you could use node.js for the notifications and PHP for your app.
By googling I found this about real-time-notifications.
You could also just use node.js with socket.io, but this means that you have to learn new technologies as you mention that you have no experience with node.
I haven't used it but you could check this project, for websockets in PHP.
When you have an update that you want to notify users you can use the publish subscriber pattern to notify the intrested in this update.
Take a look in Gearman too.
Personally, I've built a notification system using the pubsub mechanism of redis, with node.js+socket.io. Everytime that there is an update on a record then there is a publish on the appropriate channel. If the channel has listeners then they will be notified. I also store the last 20 notifications in a Redis list.
The appplication is built in PHP. The notification system is built in node.js. They are different applications that see the same data. The communication occurs via redis. For example in the Facebook context:
1) A user updates his status.
2) PHP stores this to the database and Redis
3) Redis knows that this update must publish to the status channel of the specific user and it does.
4) All the friends of the specific user are listening to his status channel (here comes node.js)
5) Node.js pushes the notification in the browser with socket.io
As for facebook, I have read in an article that is using long polling for supporting older browsers. Not sure for this though, needs citation...
AFAIK It would be via two simple methods :
First one that could be very simple is adding a Boolean column to each record that determines if it has been notified or not.
The second method is creating a table to insert all notifications.
However, I'm not sure if there are alternative methods for better performance, But first method is what I do commonly myself. But I think Facebook is using 2nd method, because it has to notify each one to a lot of users.
Your question maybe dublicate of:
Facebook like notifications tracking (DB Design)
Database design to store notifications to users
You could use Server Side Events it involves a bit of JavaScript but nothing overly complicated I think.
The main bulk of this method is PHP though, so you would just use the PHP to query your DB for notifications and SSE will push them to the user.
It does have some limitations though, most notably it's not supported by IE (huge surprise) thought i'd mention it anyway to let you know of other possibilities.
Hope this helps
I am new to the world of PHP and coding as those have helped me answer a number of questions I have posted know. I have the opportunity to jump into the deep end however seeing I have no clue about PHP and web services, I am seeking your help. I would appreciate it if you could point me in the right direction as I have not been able to find any examples nor detailed information regarding it.
Effectively there is a PHP page that needs to pass certain values to a .NET web service i.e. name, email, mobile number and upon the receipt of such information the web service sends out a text message. This is information I have so far
The Allocation service uses a basic HTTP binding and TransportWithMessageCredential security.
Sample C# code using a reference generated with Visual Studio tooling
Allocation.AllocationServiceV3Client Client = new Allocation.AllocationServiceV3Client();
Allocation.AllocateResult Result;
string VoucherCode;
DateTime ExpiryDate;
string DisplayMessageText;
Client.ClientCredentials.UserName.UserName = ? ;
Client.ClientCredentials.UserName.Password = ? ;
Result = Client.AllocateToConsumerMobileAndSendSMS(out VoucherCode,
out ExpiryDate,
out DisplayMessageText,
ClientID,
ClientReference,
CampaignID,
ActivityID,
MobileNumber);
if (Result != Allocation.AllocateResult.Success)
{
}
I have no clue about PHP and web services
First things first, pick your brain up out of the C# soup and sit it out to dry off for a few hours. PHP is a simple language for simple things. If you're new to it, you don't want to try and make it do complex things, and you certainly don't want to try writing C# style code in PHP.
Let's take "web services" as an example of a "complex" thing. In some circles, this means horribly designed monstrosities like SOAP. VS makes it relatively easy to build SOAP bindings to your existing classes, so it's not a painful solution for you.
SOAP is a very painful solution for PHP.
Effectively there is a PHP page that needs to pass certain values to a .NET web service
It sounds like you have an existing web service set up then, correct?
You could try and use the built in SOAP client, but it's an undebuggable and unconfigurable binary blob of horrors that will make you want to kill someone if it doesn't work for you immediately.
Edit: The section below was written incorrectly assuming that both sides were under your control. As this is not the case, you can disregard the rest of the answer. I'm leaving it up because it may be valuable to others.
I would advise a different approach. Set up an endpoint (URL) in your .NET application that expects the data you've specified as POST values, and have PHP POST the data. This has the distinct advantage of being incredibly simple. Because you're new to PHP, simple is a big win.
(In other words, ditch the "web service" -- or make a parallel copy if other things consume that service already.)
PHP comes with a service called PEAR, a repository of helpful classes. You can use HTTP_Request2 to quickly build the HTTP POST request. Chances are that it's already installed. If it isn't, it's easy to install either at the system level using the pear command, or locally in your project.
Here's some quick example code copied straight out of the reference guide:
$request = new HTTP_Request2('http://www.example.com/your/endpoint/url.foo');
$request->setMethod(HTTP_Request2::METHOD_POST)
->addPostParameter('name', '...')
->addPostParameter('email', '...')
->addPostParameter('mobile', '...');
$response = $request->send();
You can then read the response as needed.
Now, this isn't a perfect solution. Your C# code mentions a username and password, which I suppose could be included in the POST data. You could also use HTTP authentication (supported by HTTP_Request2) instead.
Ok, now from what I understand, C# will make a request to the php page, wich then (in simple html) gives it back some data.
PHP Is made to do some calculation serverside and when it's done it will send the prints and echo's to the client side as html (simple explanation)
If you want to start using php you would be best off getting into the basics by following the tutorials at W3School (http://w3schools.com/php/default.asp)
Then you can use http://php.net as a reference for more functions you might need.
The way you'll want to set it up is for C# to make a request to a page like action.php
And then using a $_GET method to get the data so C# would send a request to
action.php?userid='456'
I'd like to create an application where when a Super user clicks a link the users should get a notification or rather a content like a pdf for them to access on the screen.
Use Case: When a teacher wants to share a PDF with his students he should be able to notify his students about the pdf available for download and a link has to be provided to do the same.
There are several ways you can accomplish this. The most supported way is through a technique called Comet or long-polling. Basically, the client sends a request to the server and the server doesn't send a response until some event happens. This gives the illusion that the server is pushing to the client.
There are other methods and technologies that actually allow pushing to the client instead of just simulating it (i.e. Web Sockets), but many browsers don't support them.
As you want to implement this in CakePHP (so I assume it's a web-based application), the user will have to have an 'active' page open in order to receive the push messages.
It's worth looking at the first two answers to this, but also just think about how other sites might achieve this. Sites like Facebook, BBC, Stackoverflow all use techniques to keep pages up to date.
I suspect Facebook just uses some AJAX that runs in a loop/timer to periodically pull updates in a way that would make it look like push. If the update request is often enough (short time period), it'll almost look realtime. If it's a long time period it'll look like a pull. Finding the right balance between up-to-dateness and browser/processor/network thrashing is the key.
The actual request shouldn't thrash the system, but the reply in some applications may be much bigger. In your case, the data in each direction is tiny, so you could make the request loop quite short.
Experiment!
Standard HTTP protocol doesn't allow push from server to client. You can emulate this by using for example AJAX requests with small interval.
Have a look at php-amqplib and RabbitMQ. Together they can help you implement AMQP (Advanced Message Queuing Protocol). Essentially your web page can be made to update by pushing a message to it.
[EDIT] I recently came across Pusher which I have implemented for a project. It is a HTML5 WebSocket powered realtime messaging service. It works really well and has a free bottom tier plan. It's also extremely simple to implement.
Check out node.js in combination with socket.io and express. Great starting point here
Looking around for a solution to this, I have found different methods. Some use regex, some use DOM scripting or something.
I want to go to a site, log in, fill out a form and then check if the form sent. The logging in part is the part I can't find anything on.
Anyone know of an easy way to do this?
I'd agree with Les. Curl + Charles (or Fiddler, Firefox's Tamper Data extension, wireshark, etc.) is the way I've always done this. The one trick I've found is that some sites require a three step process:
Hit the login page with a GET request first to get any session ids, cookies, and/or required fields (e.g. .net sites have __VIEWSTATE and __EVENTVALIDATION).
Once you have these values, then you post to the login page
Finally, request whatever resource you're after.
Don't plan on curl's cookie jar and cookie file being much help. You'll probably be best off parsing out the session id and cookies from the headers using a simple regex.
Hope this helps!
You might be better off with some sort of scriptable browser if you need to do a lot of GUI stuff. If you need to use PHP, check out curl: http://us2.php.net/curl
what I usually do is fire up charles go through the login process in a browser and record the raw requests. Copy+paste the requests and throw them through fopen or curl (with some small adjustments according to the responses).
You may want to take a look at Perl's LWP library (I know it isn't PHP, but it's very useful for screen scraping, web unit testing, and such):
Perl LWP at CPAN
LWP::Simple tutorial
I have fair bit of experience in this. I used to use Curl but it is no fun using it. In particular many times sites exchange XSRF tokens, or pass hidden variables, or set all kinds of cookies. Tracking all this with Curl becomes difficult. Atleast for me.
I then explored Selenium and I love it. There are 2 things- 1) install Selenium IDE (works only in Firefox). 2) Install Selenium RC Server
After starting Selenium IDE, go to the site that you are trying to automate and start recording events that you do on the site. Think it as recording a macro in the browser. Afterwards, you get the code output for the language you want.
Just so you know Browsermob uses Selenium for load testing and for automating tasks on browser.
I've uploaded a ppt that I made a while back. This should save you a good amount of time- http://www.4shared.com/get/tlwT3qb_/SeleniumInstructions.html
In the above link select the option of regular download.