Parsing FIND MY IPHONE? - php

As you probably know there's that think called "FIND MY IPHONE" ( www.me.com ), that enables you to see your phones location on a google map in real time.
Yet I was thinking if there would be any way to make a PHP file that would
1. run automatically every, say, 15 minutes.
2. pass cookies with my username/password to me.com
3. retrieve the lat/long coordinates from it and save them into a database.
that way I would have a history of my phone's location.
how would you suggest doing it, can a php file pass cookies or is there something else needed? and how to retrieve those lat/long coordinates that are already shown on a google map?
Thanks!

If there aren't any limitations to this service you might be interested in reading about php cURL. Link: http://php.net/manual/en/book.curl.php
You can use cookies and login just like a normal browser.

cUrl is the best solution for your request, you can find some useful stuff here
link text

I'm sure there is an app for that ;)

Related

file_get_contents gets different file from google than shown in browser

I use file_get_contents to find out if there is an URL of the search I look at:
http://www.google.com/search?q=*a*+site:www.reddit.com/r/+-inurl:(/shirt/|/related/|/domain/|/new/|/top/|/controversial/|/widget/|/buttons/|/about/|/duplicates/|dest=|/i18n)&num=1&sort=date-sdate
If I go to this URL in my browser, a different file is displayed then what I see when I echo file_get_contents
$url = "http://www.google.com/search?q=*a*+site:www.reddit.com/r/+-inurl:(/shirt/|/related/|/domain/|/new/|/top/|/controversial/|/widget/|/buttons/|/about/|/duplicates/|dest=|/i18n)&num=1&sort=date-sdate";
$google_search = file_get_contents($url);
What's wrong with my code?
Nothing really. The problem is that the page uses javascript and ajax to get contents. So, in order to get a "snapshot" of the page, you need to "run it". That is, you need to parse the javascript code, which php doesn't do.
Your best bet is to use an headless browser such as phantomjs. If you search, you find some tutorials explaining how to do it
NOTE
If all you're looking for is a way to retrieve raw data from the search, you might want to try to use google's search api.
I assume Google is definitely checking the user agent to avoid any kind of automated searches.
So you should at least use CURL and define a proper user agent string (i.e. the same as a common browser) to "trick" Google.
Somehow I fear it will not be so easy to trick Google, but maybe I'm just paranoic and at least you may learn something about CURL.

grab a variable value from external webpage for processing?

Let me just start by saying I know almost nothing about PHP but, I think that may prove to be the best way to do what I'm trying to do. I'd like to grab the value of a variable from an external page so that I can then process it for the creation of graphs and statistics on my page. An example page that I'm trying to get the variable from (requires a Facebook Account) is - http://superherocity.klicknation.com/game/pages/battle_replay.php?battle=857337182
The variable name is fvars and it contains data about what the 2 players used for attacks, how much damage they did, etc. Ultimately what I'd like is to provide a page with a form where a player can go and plug in their replay link (like above) and get a nice neat detailed breakdown of the battle.
At the very least, if someone could explain to me how to just echo out the value of fvars after a form submission with the replay url as input it would help out immensely!!! I've tried looking at some PHP references and other posts here but, have so far been lost. :(
Thank you for any help or guidance.
One way you could approach it is to use Selenium. You would need to setup the selenium server and a browser and then write a selenium script to fetch the page for you. The key point here is that selenium can run a firefox client with javascripts, facebook logins etc, everything you have on your ordinary firefox, through selenium programmatically.
I run selenium in a Linux environment and control it through php cli scripts. I run the java selenium-server-standalone along with framebuffered X and firefox. PHP Unit test library allready has an extension though you wouldn't need it for testing obviously.
You can get the contents of any webpage like so:
$homepage = file_get_contents('http://www.example.com/');
echo $homepage;
And then just use regex or basic searching to find the variable you need in $homepage. The problem is that you need to be logged in via Facebook. I know of no current way to do this dynamically with PHP.
Mike
Edit: found an SO question that addresses this exact issue - Scraping from a website that requires a login?

Extract information from javascript counter via PHP

I'm looking for a way to extract some information from this site via PHP:
http://www.mycitydeal.co.uk/deals/london
There ist a counter where the time left is displayed, but the information is within the JavaScript. Since I'm really a JavaScript rookie, I didn't really know how to get the information.
Normally I would extract the information with "preg_match" and some regular expressions. Can someone help me to extract the information (Hrs., Min., Sec.) ?
Jennifer
Extracting the count-down time is not going to be easy, because it is fetched and set purely using JavaScript, which cannot be parsed using pure PHP. You would have to de-code the JavaScript code and see what calls it makes to fetch the initial times.
That is not an easy process, and could be changed by the site owners in no time.
Also, doing that, you would be in clear breach of their T&C:
For the avoidance of doubt, scraping of the Website (and hacking of the Website) is not allowed.
I hate to say "no", but in this situation PHP is not the right job for this. JavaScript requires a browser to run (in this case) and on top of that you probably have a jQuery lib.
The only thing PHP could do is invoke a browser that would contain some JavaScript (i.e., GreaseMonkey) that could try and scrape the page for the info. But this is really a job for embedded JavaScript.
As the others have said you can usually not access JavaScript stuff from PHP. However JavaScript has to get its data from somewhere, and this is where to start.
I found this in the source code:
<input type="hidden" id="currentTimeLeft" value="3749960"/>
That's the number of microsecond until whatever it is.
However this was only present in firefox, not when fetching it with wget. I found out it's the cookie that matters, so you'd have to request the page once, store the cookies and then access it a second time.

how do you take a snapshot of your current browser window using php

I've tried searching everywhere but there's seems to be no implementation available other than having the client use a file (batch/exe of some sort).
You just can't do it. PHP is server side scripting language, maybe you can do that using JavaScript, but I'm not even sure about that.
I know someone implemented such service, but actually he had to use Mozilla browser, which opened, a script (I think it was not JS, maybe perl, c/c++) made a screenshot and uploaded it.
I'm assuming you mean "your" in the general sense. If you mean "how does one take a screenshot...", you generally hit the print screen key. If you're trying to capture your users' browser output, I'd say that it's probably not possible. If it were, the best you could get is the output of what you wrote yourself.
Google Gears might be hackable to do something close, if you can simulate the print screen key press with JS and get the file to save somewhere gears can access.
You can't do that in PHP, as PHP is running on the server, and not the client.
To get screenshots of the browser, you can take a look at, for instance, this list.
If you are look for an automated solution to take screenshot of web pages opened in a browser window, you could also look at this question : How to capture x screen using PHP, shell_exe and scrot and it's answers.
And, finally, and without selecting any particular post, you can try a search on SO ; something like screenshot browser, sorted by relevance, seems to get some interesting posts :-)
Good luck !

Is there a way to automatically take a screenshot of a website through a URL?

I am trying to find a PHP script (or a script in a different language) that after passing a URL, it takes a screenshot of the website for that URL. So for example if I pass stackoverflow.com, it should take a screen shot of the website (in this case the homepage), keep it on the server, and provide a link to that pic.
Is there an easy way to do that?
I know it is possible because that's how they take thumbnails for websites in Alexa for example.
If you need more explanation of what I mean please just post a comment and I will explain more.
Thank you :)
Start a Browser (like system("firefox [url]")), run a screengrabber for that window and save the image somewhere.
Since the output is always depending on the render engine used it is not possible by using php alone.
Other option would be to embed a rendering engine (Gecko or similar) into your php script.
You can use browsershots.org service or litmusapp.com.
Both of these will generate screenshot of a page. You can then download the screenshot and use it in a way you need to.
Something like Litmus?
Browsershots normally has their backend source code available, but as of this answer, it appears to be offline at the moment. There is an outdated mirror on Github which you can look at.

Categories