Could I know what has been changed lately in the file? - php

I'm doing some development and my company does use excel to edit database (I don't agree but, hey... hate the game, not the player! :D ). So, to avoid some encoding problems, I aiming to put it to Google Drive because it's very unlikely to change this sort of things the Microsoft insists in change every d**m version.
What I'm trying to do is: receive a file from Google Drive with only the fields that has been lately manipulated (or even receive the entire file, but somehow I could know the last changes), put it on a variable and manipulate it. I don't have the need to edit de excel file itself. It's going to be on Google Drive's interface. I only need to read it.
NOTE 1: I was using this doc (https://developers.google.com/drive/manage-changes) , but it appears that the API only says if either the file has been changed or not. I would be very nice if I could know what has been changed in the file. It would avoid me a overload in the database (I'll have to re-write the ENTIRE DATABASE).

It's impossible to retrieve field changes, but you can retrieve a change history by listing changes.
https://developers.google.com/drive/v2/reference/changes

You probably want to check Revision.
Google Drive provides file revision and you can get list of changes using this API

Related

How to hide php codes and mysql table schema

We've a Clint requirement in which, all the PHP source codes + MySQL DB will be in their network. So all their data will not be visible to outside world. That's we can do.
But, the thing is.. we want to hide our source codes(PHP) & MySQL DB from them(client). So that no body can make any miss use of those.
For PHP i think "ZEND GUARD" will be a good choice. But, still.. i want to know is there any other better tools available in web for hiding PHP source codes.
About, hiding MySQL DB.. we've no idea how to deal with this. But, more specifically we want to hide our all tables SCHEMA. So that, no body can access all those information.
Any idea guys..
Regards
For php codes you can write some dll files which contain your functions and that is how you can code them. for that see here
and for your mysql you can put it on another server and give access to people you need.by the way you can make as many users in a db as you want and give them the specific accesses. for that see here

Identify a file that contains a particular string in PHP/SQL site

By using the inspect element feature of Chrome I have identified a string of text that needs to be altered to lower case.
Though the string appears on all the pages in the site, I am not sure which file to edit.
The website is a CMS based on PHP and SQL - I am not so familiar with these programs.
I have searched through the files manually and cannot find the string.
Is there a way to search and identify the file I need using, for example, the inspect element feature on browsers or in FTP tool such as Filezilla?
Check if you have a layout page of any kind in your CMS. If you do, then most probably either in that file, or in the footer include file you will find either the javascript for google analytics, or a js include file for the same.
Try doing a site search for 'UA-34035531-1' (which is your google analytics user key) and see if it returns anything. If you find it, what you need would be two lines under it.
Usually people do not put analytics code in DB, so there is a bigger chance you will find it in one of the files, which most probably is included/embedded in a layout file of some sort, as you need it across all pages in the site

How to download information from a website

I'm trying to automatically download information from a website based on a few parameters. Essentially I want to specify the parameters of a search and have the function automatically navigate to the appropriate website and download the file. Note that all of the files are excel file, usually .csv.
Here's the website:http://comtrade.un.org/db/
NOTE: This websites address will be updated depending on the search, so, for instance, if you search trade from the united states to iran (The rest of the parameters are unspecified), the result is:
http://comtrade.un.org/db/dqBasicQueryResults.aspx?px=HS&cc=TOTAL&r=364&p=842&rg=1&y=2010,2009,2008,2007,2006&so=8
More on this here:
http://unstats.un.org/unsd/tradekb/Knowledgebase/Data-Extraction-Using-Comtrade-Web-Service
Look under web service methods and parameters
Two Question:
1) How can I do this?
2) What is the best language to do this in?
There is just no "best language". You can do this by any language with HTTP access availability, this could be either PHP, Java, RoR, Perl, Python...
On the link you posted, you can read they are offering REST service for accessing the data in XML.
In PHP, you would first have to download the file using appropriate URL:
$xml = file_get_contents("http://comtrade.un.org/ws/...");
Than use PHP's XML functions to parse the file.
I'm not sure about their license of data usage - you might not be legally permitted to automatically download data from here.
UPDATE
You cannot directly download the files found in the search results (through PHP e.g.) - so you HAVE to use the REST access, but some parts of it are obviously accessible only if UN allow you to do so. If you would try to download directly the "excel" (in fact CSV) files, you will end up with error like this: http://comtrade.un.org/db/dqBasicQueryResultsd.aspx?action=csv&px=HS&cc=TOTAL&r=364&p=842&rg=1&y=2010,2009,2008,2007,2006&so=8. You can spoof the HTTP_REFERER value, but you will break the terms of the service.
In PHP, use file_get_contents("http://............");
Plug in whatever URL and GET parameters you want, and you instantly have the data, in this case the CSV, which you can then process.

verifying a domain using php

I have a member area, where they can add their domains and it will be displayed in the profile page..but now I want to add a verification process, just like google web-masters does..where they need to upload a certain file and so..
please tell me whats the best way to do this ?
Thanks :)
Generate a token for each domain (sha-1 of domain or so), store it in your DB or what have you.
Generate a text-file containing the token on user request.
Ask the user to inform you to poll or poll every now and then to check the URL. This can easily be done by file_get_contents in PHP if fopen_wrappers are enabled.
The token is obviously compared to the token in your DB to make sure it wasn't just a random file present at a random domain..
Could be a good idea to check at some time interval if the file is still there, to keep someone from selling the domain but remain in control
It's not really black art as we can assume the user has access to its domain once any specific request which proves access can be fulfilled by the user. There's no real way to fool the system except doing some DNS-magic, or gaining entry to the webserver running on the domain, which is out of your control anyway.
Not sure if that's the best way, but I think Google does something like this:
get user's domain name (e.g. "http://example.com")
generate unique code and store in db
tell user where to upload the code (e.g. something like "/verification.txt")
after confirmation, make a HTTP request for the code ("http://example.com/verification.txt") from own server to the user's server
compare the code you received to the code in the db
You may want to generate consistently the same code for the same domain.
This question is convoluted. I think you need to spell out what you are looking for a little better.
EDIT #1:
Generate an md5 and give it to the user, tell them to put it on their domain and provide a URL to where it is. This could be in a txt file or anything.
Then read that file and check if the md5 string exists in there.
Actually I would come up with something slightly different than an md5. Maybe three of them, so that you reduce the chance they find it on some other domain and then give you that URL.
This can still be spoofed unless you nail down constraints, like it has to be a text file, the file must only contain the md5... etc.
Right now I can type in an md5 but it doesn't mean I control this website:
md5("i fooled you") = "0afb2d659b709f8ad499f4b87d9162f0"
But if I handed the URL to this answer, your system might accidentally think I have admin here.
I recommend creating a file and making them upload the file and give you the URL to it. But even that won't necessarily work because there are many sites where you can just upload something.
Maybe if it's a php encoded file that can execute? That's kind of a security flaw because I don't know if I would upload just anyone's PHP file. Typically if you don't have admin nobody is going to let you upload a php file that would work.
You might want to create a php call-home script but that's gonna be bad. People wouldn't use it.
Another way it could be done is:
Get the domain name
Generate a random code/string.
Sore this in your database
Make a meta tag and the random code in the content.
Use file get contents of the index page of the website.
Then search the page for the meta tag with the code sorted in the database.
If statement for success or unsuccessful.
The meta tag should look like this:
<meta name="site-verification" content="1010101010101010101010101010101010101010" />
Actually, just creating an md5-string for the domainname, letting the site owner put that in a meta-tag so you can check that would allready work fine ...

Does a PHP library exist to work with PRC/.mobi files?

I'm writing a WordPress plugin to create an eBook from a selected category in most major eBook formats. I would like to support MobiPocket since that's the format used by the Kindle but I'm not sure how to go about it. From what I've read .mobi files are actually Palm Resource Databases (PRC) but I haven't been able to find a PHP class to work with these.
I thought about using exec along with KindleGen but that would be undesirable as it would complicate initial setup. I've also thought about hosting a web service somewhere and using XML-RPC to accomplish this but that also complicates things.
My question is: is there a PHP class/library (PHP-only preferred) that can work with PRC or even better, a class that specialises in creating MobiPocket ebooks? (needs to be open source since I'm releasing under the GPL)
I've tried searching but haven't been able to find anything.
I don't know whether you're still looking for this PHP library, but just in case: https://github.com/raiju/phpMobi. This is a library that creates mobi files from html files.
It's should still be seen as an experimental version, but it should work without a problem for basic document with a few images.
Unfortunately not; however, the binary compiled format is an open specification available at:
http://www.mobipocket.com/dev/article.asp?BaseFolder=prcgen
The only direct way of transforming the uncompiled format is using the native XML functionality of PHP to create them and then invoking a compiler with exec, which I understand you don't want to do. If you go with this route, the link above also has details about this XML format.
You might want to try the mobiperl tools,
https://dev.mobileread.com/trac/mobiperl/wiki
Please note I haven't tested them yet. But they have been
around since at least 2007 so they should work well by now.
google "Mobiperl - Perl tools for handling MobiPocket files" to
find a thread on mobileread board discussing it. As a new
poster I can't put 2 hyperlinks into my reply.
Another tool I have recently found (but not yet tested), is: http://www.phpclasses.org/package/8173-PHP-Generate-Kindle-ebook-file-in-mobi-format.html#files
It is based upon KindleGen, and looks pretty straight forward to implement.

Categories