Monday, May 03, 2010
Package php-doc missing in Ubuntu Lucid
After installing the new Ubuntu Lucid I discovered that the package php-doc is not available anymore. Since I often work offline, having the php documentation installed to be browsed offline is a must for me.
It looks like for the moment that package is not available due to build failures.
Fortunately, the package for karmic can be installed without any problem, and you can download it from here. :)
Wednesday, March 03, 2010
CakePhp and SSL connections (https)
I've been playing with CakePhp for some time now (and really enjoyed and enjoying it), since I'm turning my bibliography system, PhpBibliography, to use it (I've rewritten it basically from scratch using cakephp, and hopefully the new version will be out soon).
What I've been struggling with was the https ssl connections which didn't seem to work: I was getting page not found errors, and even after the ssl site was working, only the home page seemed to respond, but no css style was applied.
The problem was due to the rewriting engine on which cakephp is based on, and I had not configured it correctly in the apache site (so cakephp was not to blame). I document my experience here hoping it can help others.
I'm using Ubuntu 9.10, so what follows was done on such system.
First of all, you need to enable ssl in apache; To enable SSL, type (as user root, e.g., with sudo):
a2ensite default-ssl
a2enmod ssl
Note that I'm not interested here in creating a specific certificate, so I'm using the default one.
Then, you need to make the mod_rewrite work also for the ssl site: you need to edit /etc/apache2/sites-enabled/default-ssl and make sure that AllowOverride is set (in my case I only need that in /var/www):
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Then, restart apache and your cakephp will work with https as well.
Pubblicato da betto a 12:55 PM 3 commenti
Thursday, June 11, 2009
Php-source-highlight
Just after one week I released version 3.0 of source-highlight with the C++ library, I got an email from Pascal Bleser, telling me that he created a php extension using the library, for highlighting code from php without relying on CGI scripts! You can find its plugin extension here: http://code.google.com/p/php-source-highlight. I took a quick look at his code and it's really simple and clean, hopefully this also means that the library of source-highlight can be smooth to use :-).
You can also might want to take a look at his blog post!
Pubblicato da betto a 8:58 PM 0 commenti
Etichette: php, source-highlight
Monday, December 22, 2008
PhpBibliography 0.6
The new release of PhpBibliography is out!
First of all, this release fixes a very bad bug, discovered by Ezio Bartocci: in the merge authors procedure, the system did not check whether the two authors were exactly the same (i.e., the same id), and this used to lead to the removal of the author as the final step of the procedure, which was really bad. This is now fixed in this new release.
Concerning new functionalities:
- a procedure for trying to detect duplicate papers is now available (it can also use the SOUNDEX algorithm); this will present possible duplicate papers, and let the user select those that are actually duplicate ones;
- as for the main page, it is now possible to group papers also according to the years (an example can be found at my home page);
- by default, papers are ordered by descending year, so that the most recent papers are shown first (this should be the most common wanted behavior);
- a modification timestamp is automatically added to papers, and this timestamp is used as a sorting criterion when showing papers (the papers most recently modified are shown first)
- another desirable feature is now available: when listing papers in administration mode (i.e., when you're logged), a direct edit/delete link is always shown;
- each paper can be now marked as private, meaning that that specific paper will be shown only to logged users;
- as for the DBLP import procedure, this was improved: when there is a cross reference (typically concerning the proceeding book where the paper was published), which is separate from the paper's own bibitem, the system will merge the two bibitems, so that the resulting inserted paper will contain all the information.
The user specifies a non-numeric year
and the system checks it as soon as it leaves that field.
The same holds for instance for the title, but this time it's just a warning (since you can have two papers with the same title, e.g., one can be an extended version):
Pubblicato da betto a 7:38 PM 0 commenti
Etichette: php, phpbibliography
Wednesday, August 27, 2008
MyIpTrack: keep track of the IP addresses you use
I've just released a new program, which is actually a php script to install on a web site.
MyIpTrack is a php script that allows you to store the IP addresses with which you connect to the Internet. It stores such information on a text file. The information stored are: the IP address, date and time and some notes.
This is pretty useful if you connect to the Internet with many different providers (wireless networks, Internet cafe, etc.) and you want to keep track of all the IPs you've used (and date and time). You can also fill some notes for each such record.
MyIpTrack only needs a web server with PHP; it does not use any database: it stores the information in a text file. The archive consists of a record per line (thus records are separated by newline characters), and fields are separated by a tab character:
IP TABdate TAB address TAB notes
How it works
The idea is that when you connect to the Internet, you visit the page where you put MyIpTrack; at this point you'll be presented a web form already filled with the IP, the date (and time) and the address corresponding to the IP you are currently using. Then you'll be able to add some notes (e.g., that help you remember for what you used that IP).
If you're using an IP that you've used before, MyIpTrack will show a table with all the dates you used that specific IP.
It also shows a table with all the IP addresses used in the past. See the screenshot below.
License
MyIpTrack is Open Source, under the GPL license.
Installation
After you downloaded the .zip file and extracted its contents, all you need to do is copy the contents of the directory html into a directory of your web server. Make sure to give full write access to the text file where the information will be stored: archive.txt.
MyIpTrack is not thought to be part of a public web site: its web page is considered to be used only by the user who installed it, so it should be put in a private web directory. However, MyIpTrack provides also a basic authentication mechanism based on a user name and a password, specified in the file config.php. Just leave the user name empty if you're not interested in the authentication. If you want to use authentication, change the user name and password.
Pubblicato da betto a 5:58 PM 0 commenti
Etichette: my programs, myiptrack, php
Sunday, August 24, 2008
PhpBibliography 0.5: RSS & DBLP import
It is with great pleasure that I announce this new release of PhpBibliography!
First of all, I really need to thank Ezio Bartocci, a PhD candidate of University of Camerino, Complex System Research Group, who did a wonderful job in implementing the two new main features of this release: RSS and DBLP import.
RSS
Basically, every query page now also generates an RSS link that can be used to subscribe to that specific result as an RSS feed. Of course, that feed is dynamic, so each time your RSS reader will look for updates, the system will actually run the query again. This is pretty useful to generate an RSS feed for a specific author's papers.
For instance, this is the output of my papers, and you can see the RSS link on the right that can be used to subscribe to my papers feed. As soon as a new paper of mine is added to the system, the RSS reader will catch that. And this is the direct RSS feed.
DBLP paper import
The other cool feature that Ezio implemented is the possibility of importing papers directly from DBLP, the Computer Science Bibliography, using the bibtexs of this site.
This feature is still experimental and we will have to twickle it a little bit, but it seems to work for most of the cases.
You'll be asked to insert your name and surname. After you inserted the author's name and surname,
the DBLP site will be queried and all the author's found papers will be presented to the user; the system will already check which papers are similar
to those already present in the database; if a similar paper is found in the database that entry will not be automatically selected for the import (and will be highlighted in red); the other papers will be automatically selected for import.
The user will then be able to further select all the papers to import, and
press the import button (it is also possible to select all the papers or all the papers of a specific year). Note that the procedure might require some time. Finally, you'll be able to edit each single paper imported through this procedure.
Note that the bib items of DBLP might not produce such nice paper records in phpbibliography, especially when they cross reference other bib items (also shown as a result, but not inserted in the data base); you'll probably need to modify such imported papers using the additional information in the cross referenced bib item. We are working on how to solve this little issue.
Again, let me thank Ezio once again! Not only he did a great job, but it was also very funny to work with him through instant messaging :-)
Pubblicato da betto a 6:04 PM 0 commenti
Etichette: php, phpbibliography
Friday, August 03, 2007
"Last Modified" in PHP
This is nothing exciting, but I just wanted to share :-)
If you want to put in your php web page the well known "Last Modified: " you can simply put this code:
<?php
echo "<b>Last modified:</b> " .
date( "F d, Y. H:i:s a", filemtime("YOUR FILENAME") );
?>
where, of course, you must substitute YOUR FILENAME with the filename of your web page.
That's it!
Pubblicato da betto a 3:55 PM 4 commenti
Etichette: php
Friday, February 23, 2007
Grab the content of the html body in Php
It's quite usual to use the include function of php to include html files into another html or php file. In order for the resulting output to be a correct html output, the html header should appear only once (and outside the body). Thus, the included html files should not contain the header, but only the body contents. If, however, you write all these html pieces using a WYSIWYG editor, these html will end up having their own header.
Thus, when including these html pieces from a php file, you should strip header (and closing html tags), and get only the contents included in the body tag. By using regular expressions it's pretty easy to do that.
This is my simple implementation:
<?php
/**
* Returns the body content of the specified HTML file.
*
* @param string $filename
* @return string
*/
function getbody($filename) {
$file = file_get_contents($filename);
$bodypattern = ".*<body>";
$bodyendpattern = "</body>.*";
$noheader = eregi_replace($bodypattern, "", $file);
$noheader = eregi_replace($bodyendpattern, "", $noheader);
return $noheader;
}
?>
Pubblicato da betto a 10:22 AM 10 commenti
Etichette: php
Thursday, February 15, 2007
Eclipse, Php Ide and Gentoo
As I said yesterday, I successfully installed eclipse and phpide in my Gentoo box. I had also set up the link to mysql socket, as I had explained in my previous post.
However, as soon as I tried to run a php script that uses mysql functions I got this error:
Warning: mysql_connect() [function.mysql-connect]: Client does not support authentication protocol requested by server; consider upgrading MySQL client in /home/bettini/workspaces/php/dbtophp/share/db.php on line 23
could not connect to database
Fortunately, this is a known error in mysql documentation: http://dev.mysql.com/doc/refman/5.0/en/old-client.html.
In fact, I just did what that page says, i.e., reset the password to the "old" style:
mysql> SET PASSWORD FOR 'some user'@localhost = OLD_PASSWORD('your password');
and the error went away.
Probably this was due to the fact that mysql is version 5.0, but the php engine that comes with phpide (and that I use for running and debugging scripts from within Eclipse) still uses the old mysql functions for connecting to the database.
Wednesday, February 14, 2007
Apache2, PHP, MySql (Gentoo Linux)
I've just installed Apache, Php and MySql in my Gentoo box; I've always used these programs and servers only under Debian since they looked easier to install (or probably they looked harder to install in Gentoo :-). I actually found out that it's quite easy to install them in Gentoo either!
I followed some documents found on the web, but basically the installation procedure was even faster than that found on the web:
I put these lines in /etc/make.conf:
USE="apache2 mysql php pam ssl xml xml2 berkdb innodb jpeg png"
If you want to install also phpmyadmin, then you should also add pcre session unicode:
USE="apache2 mysql php pam ssl xml xml2 berkdb innodb jpeg png pcre session unicode"
then I simply ran:
emerge dev-db/mysql apache php
after few minutes (well... half an hour would be more appropriate) the installation terminated successfully.
I then changed the file /etc/init.d/apache2, in order to enable public_html folders for users (corresponding to the ~ directory), setting -D USERDIR:
APACHE2_OPTS="-D DEFAULT_VHOST -D PHP5 -D USERDIR"
Before starting mysql, you must create (once and for all) the mysql main database, and this can be done simply by running:
/usr/bin/mysql_install_db
then you're ready to start apache and mysql.
Wednesday, December 27, 2006
PhpBibliography 0.4 - web based bibliography system
I've released version 0.4 of PhpBibliography, http://phpbibliography.sourceforge.net, a web based bibliography system that allows you to publish your bibliography online (and to edit it via web). It is implemented in Php and uses MySql. This is free software, open source, released under GPL.
There are many new features in this release (I hope you find useful).
First of all, you can also modify a paper by using a bibtex (previously you could only insert a new paper by using a bibtex). For this reason, the bibtexkey field was added to the database (and w.t.r. I added also the function in the admin menu to automatically generate bibtex key for papers which do not have it yet). Furthermore, you can also upload an entire bib file; this will allow you to set up the bibliography site with only one action (of course you'll then be able to modify each inserted paper).
Papers can now be classified according to several criteria (called classifications), not only by using categories. You can add new classifications, and for each classification you'll be able to add values that can be associated to papers. For instance, you can have the classification "keyword", the classification "status" with values "submitted", "to appear", "published", etc. This is very useful also for (virtually) adding a new field to the paper table structure. Classifications can be related to a specific bibtex field, so that they can be retrieved from bibtexs (and also generated in the corresponding field, during the automatic bibtex generation).
A functionality was added (available from the admin menu) that allows you to "merge two authors" that, due to a mistake, represent the same author. (This usually happens when inserting a paper through a bibtex.) For instance you have two authors Foo Bar and Foo T. Bar that represent the same author. With this function, the system will replace the second author with the first author (i.e., the second author will be deleted and all the papers that were associated to the second author will be associated to the first author).
From the paper presentation point of view some customization features were added: you can pass additional parameters in the URL (you can also specify them in the config.php file, but the ones passed on the URL will take the precedence). Here we list these parameters (in the URL they must be passed without the ,ドル using the GET passing method syntax) and their default values:
- $printfilenames = "1"
This tells the paper formatter whether to name the link to the paper source using the complete name of the file (e.g., my_paper.ps.gz). If set to "0", then only the extension of the file will be shown (e.g., ps.gz). - $linktodetails = "1"
The title of the paper will link to a separate page with complete details about that paper. If set to "0", no link will be generated. - $noheader = "0"
If set to "1" the generated page will contain no header information (i.e., it will not even contain the css definitions). This is useful when you want to include the output of phpbibliography into another web page and you want customize it with your own css definitions. - $paperorder
Specify the sorting criteria of the shown papers. For the moment the only possible value for this parameter is title (meaning that papers will be ordered according to their title).
while the next one shows the output where printfilenames is set to "0"
Finally, some bugs were fixed (in particular the authentication problem in php 5, due to the use of wrong variable names, see also this post on this blog).
Hope you enjoy this new version of PhpBibliography (yeah, I know, the logo is not that beauty, but that's just the beginning :-)
Pubblicato da betto a 7:13 PM 2 commenti
Etichette: mysql, php, phpbibliography
Saturday, December 23, 2006
Strpbrk in Php
In Php 5 the string function strpbrk was introduced (quoting from the manual):
string strpbrk ( string haystack, string char_list )
strpbrk() searches the haystack string for a char_list, and returns a string starting from the character found (or FALSE if it is not found).
This is quite useful in many cases, but unfortunately it's not available in Php 4. However, it should be quite straightforward to implement it. Here's how I did:
function my_strpbrk($haystack, $char_list) {
$pos = strcspn($haystack, $char_list);
if ($pos == strlen($haystack))
return FALSE;
return substr($haystack, $pos);
}
And this is its usage:
<?php
require_once("strpbrk.php");
$text = 'This is a Simple text.';
// this echoes "is is a Simple text." because 'i' is matched first
echo my_strpbrk($text, 'mi');
// this echoes "Simple text." because chars are case sensitive
echo my_strpbrk($text, 'S');
// returns FALSE
print (!my_strpbrk($text, 'W') ? "FALSE" : "TRUE");
?>
Just my two little cents :-)
Pubblicato da betto a 12:45 PM 1 commenti
Etichette: php
Monday, November 27, 2006
Problem with PHP $HTTP_POST_VARS
In my program PhpBibliography, http://phpbibliography.sourceforge.net, see also the announce on this blog, I've always used the same authentication code that had always worked and I never noticed that it was still using the array $HTTP_POST_VARS, instead of $_POST.
As far as I knew they worked the same... well, a user told me he experienced problems in authenticating, and after some time spent on thinking it was due to sessions and cookies we realized it was due to the fact that the form did not pass anything... the $HTTP_POST_VARS was not defined.
Well, also the documentation of PHP 5.0 says that this array may be disabled. Now everything uses $_POST :-)
Pubblicato da betto a 12:19 PM 1 commenti
Etichette: php
Wednesday, October 25, 2006
I love Static Typing
I know it's a great debate: static typing vs dynamic typing. I definitely prefer statically typed languages. Lots of type errors in programs are detected during the compilation and not during the execution of programs. I think this way programs are far more reliable. It might be tedious to declare variables before using them, and specify their types, but the time you "waste" in this operation is surely repaid when you won't have to test your program thoroughly just to be sure that there are no situation where your program goes wrong because it misuses a variable. Even worse when the program silently uses a variable that is not defined.
Although I like PHP very much, I find it really irritating when your browser shows an error in your dynamic web site because you used a function that is not defined (probably just because you misspelled its name). Not to mention when your program silently misbehaves (without no sign of error) just because you used a variable that is not defined (and in that case it simply instantiates a variable with an empty value).
If a program is type-checked at compile time, it won't have to be re-checked (or at lease, completely rechecked) at each execution time (and I think you gain a lot in efficiency).
When I have to test my programs, I prefer to concentrate on the right implementation of the program logic, rather than to check whether I used the right types. That should be compiler's work.
Of course, dynamic typing is good under certain circumstances (dynamic loading of code); but for the other situations, I feel more comfortable and safe with static typing.
As you might have guessed, this post comes after some time spent on debugging a program that misbehaved just for this reason :-)
Just my opinion :-)
Pubblicato da betto a 3:57 PM 0 commenti
Etichette: php, static typing
Thursday, October 05, 2006
PhpBibliography 0.3 - web based bibliography system
I've released version 0.3 of PhpBibliography, http://phpbibliography.sourceforge.net, a web based bibliography system.
PhpBibliography allows you to publish your bibliography online (and to edit it via web). It is implemented in Php and uses MySql. This is free software, open source, released under GPL.
The main features of the system are:
- stores all papers details in a SQL database
- handles uploads of files (e.g., .pdf of papers)
- automatically generate bibitems
- supports insertion of papers through existing bibitems
- allows paper search and filter (e.g., authors, title, keywords, etc.) mechanisms
Papers are all stored in a common database, and can then later be filtered according to a specific authors so that each author can show his/her own papers in his/her own page (for instance at http://www.lorenzobettini.it/papers the papers shown are collected from two different phpbibliography installations; the papers are included in this webpage by using a remote URL inclusion mechanism by specifying, in URL the filter criteria -- in this case, the filter is to show only my papers).
Pubblicato da betto a 11:46 PM 0 commenti
Etichette: mysql, php, phpbibliography
Saturday, September 30, 2006
Eclipse & Php: Php Ide
Eclipse is a wonderful IDE for programmers (extensible with plugins and for new programming languages) and I really enjoy using it! A sort of the Emacs of the new millennium (I'll keep on using Emacs too, though :-)
The Zend plugin for programming in Php with Eclipse, Php Ide also looks very promising! I started using it few weeks ago and found really helpful and powerful. It features syntax completion and an easy to use debugger (although I still haven't succeeded in debugging php programs as web servers).
Here's a screenshot during debugging:
I found it very productive and it is always kept upgraded (the version I'm trying is 0.2.4).
One of the problems I had was due to the use of MySql: when I run a php application I used to get this error:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2) in...This was due to the fact that the configuration of php used by php ide expects the socket for connecting to MySql server in /tmp/mysql.sock, but the Debian system I'm using is configured so that the mysql socket is actually in /var/run/mysqld/mysqld.sock.
Since I didn't find a way to configure this option in the php used by php ide, I simply create a symbolic link before starting php ide:
ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock
With this "hack" I have no problem at all :-)
Pubblicato da betto a 5:02 PM 12 commenti