Skip to main content

Posts

Showing posts from May, 2010

How to Self-Sign an SSL Certificate

To self-sign SSL certificates using openssl, you will need to set up your own certificate authority using the following steps. Generate a key for your certificate authority openssl genrsa -des3 -out server.key 2048 Remove the password from your server's key. This step is optional, but is required to get the below Perl script to work. Obviously you wouldn't do this to a real key that you had signed by a real certificate authority. cp server.key server.key.org openssl rsa -in server.key.org -out server.key Generate a CSR for your certificate authority. openssl req -new -nodes -key server.key -out server.csr Sign your certificate request openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt Now you can sign certificate requests. Here is an example for a CSR named test.csr openssl x509 -req -days 365 -in test.csr -out test.crt -CA server.crt -CAkey server.key -set_serial 01 Optional: Add your certificate authority to your browser so you don'...

Getting Next and Previous Item by ID From MySQL Database With PHP

If you know the ID of an item you want to get from a MySQL database with PHP, but you also want to get the next and previous items when the IDs are in numerical order but may contain gaps due to deleted items, you can do something like this: $curID = NULL; $curRow = NULL; $prevID = NULL; $nextID = NULL; $lastID = NULL; // Get the latest one (for the "Last" link) $result = mysql_query("SELECT itemID FROM tableName ORDER BY itemID desc LIMIT 1"); $row = mysql_fetch_array( $result ); $lastID = $row['itemID']; // Get the ID for the requested item if (isset($_GET['curID'])) { // if $_GET['curID'] defined, use it as curID $curID = $_GET['curID']; } else { // Use the latest one $curID = $lastID; } // Get requested row and next/prev rows if they are there $sql = " SELECT * FROM tableName WHERE tableName.itemID IN ( (select itemID from tableName where itemID < $curID order by i...