CodeIgniter Session Cookie
I found something "peculiar" about how codeigniter stores session cookies.
CodeIgniter allows you to encrypt your cookie using sha1 which requires an encryption key, but it's not set by default.
A typical CI cookie looks like this:
a%3A9%3A%7Bs%3A10%3A%22session_id%22%3Bs%3A32%3A%22e56862bcb9fe688cb8806b7067b06b7f%22%3Bs%3A10%3A%22ip_address%22%3Bs%3A13%3A%22192.168.0.124%22%3Bs%3A10%3A%22user_agent%22%3Bs%3A50%3A%22Mozilla%2F5.0+%28Windows%3B+U%3B+Windows+NT+6.1%3B+en-GB%3B+rv%22%3Bs%3A13%3A%22last_activity%22%3Bs%3A10%3A%221262120952%22%3Bs%3A4%3A%22user%22%3Bs%3A1%3A%227%22%3Bs%3A3%3A%22rol%22%3Bs%3A1%3A%221%22%3Bs%3A4%3A%22giro%22%3Bs%3A1%3A%221%22%3Bs%3A5%3A%22lugar%22%3Bs%3A2%3A%2250%22%3Bs%3A6%3A%22logged%22%3Bs%3A1%3A%221%22%3B%7D37a9099621cf8f09b531e91c327b4b9d
Which is URL Encoded. A simple UrlDecode gives us:
a:9:{s:10:"session_id";s:32:"e56862bcb9fe688cb8806b7067b06b7f";s:10:"ip_address";s:13:"192.168.0.124";s:10:"user_agent";s:50:"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv";s:13:"last_activity";s:10:"1262120952";s:4:"user";s:1:"7";s:3:"rol";s:1:"1";s:4:"giro";s:1:"1";s:5:"lugar";s:2:"50";s:6:"logged";s:1:"1";}37a9099621cf8f09b531e91c327b4b9d
Which is way more readable. Basically, single letters are the data type (a => array, s => string, i => integer). Then, the length of the field and then the value. (length is omitted on integers).
The last 32 hex digits is the MD5 hash. I found out that if you trim the hash away, and you modify your data, you can "re-hash" it, and append the new hash to your data.
Then, you just UrlEncode your data again, and modify your cookie.
Amazingly... it works.
Microsoft Jet DB Engine doesn’t like 64bit Windows
Apparently, Microsoft never released a 64bit version of it. Change target platform to 32bit and you should be alright.
DataGridView EditOnEnter and row deleting
When you're working in a datagridview, sometimes is useful to use the EditOnEnter edit mode.
But for some reason (i.e. Bug) the deleting functionality is broken under this scheme.
To overcome this, you could use this little hack.
You'll need 2 events:
CellEnter
private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e) { DataGridView dgv = sender as DataGridView; if (dgv != null) { dgv.EditMode = DataGridViewEditMode.EditOnEnter; } }
MouseClick
private void dataGridView1_MouseClick(object sender, MouseEventArgs e) { DataGridView dgv = sender as DataGridView; if (dgv != null) { DataGridView.HitTestInfo hti = dgv.HitTest(e.X, e.Y); if (hti.Type == DataGridViewHitTestType.RowHeader) { dgv.EditMode = DataGridViewEditMode.EditOnKeystrokeOrF2; dgv.EndEdit(); } } }
Importing data directly from Excel
using System; using System.Collections.Generic; using System.Data; using System.Windows.Forms; using Excel = Microsoft.Office.Interop.Excel; namespace ExcelImport { public partial class Form1 : Form { public Form1() { InitializeComponent(); System.IO.FileInfo info = new System.IO.FileInfo("C:\\cosa.xls"); this.openFileDialog1.FileName = "*.xls"; DataTable dt = new DataTable(); dt.Columns.Add("ID"); dt.Columns.Add("Name"); dt.Columns.Add("Date"); dt.Columns.Add("Last Name"); dt.Columns.Add("Address"); if (this.openFileDialog1.ShowDialog() == DialogResult.OK) { /* For some reason, all excel lists and "arrays" are not zero based. * This is important to keep in mind while looping thru everything */ Excel.Application ExcelObj = new Excel.Application(); //I really don't know what the other 13 or so parameters do, but i swear this works Excel.Workbook theWorkbook = ExcelObj.Workbooks.Open(openFileDialog1.FileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); Excel.Sheets sheets = theWorkbook.Worksheets; Excel.Worksheet worksheet = (Excel.Worksheet)sheets.get_Item(1); /* This is neat. Only retrieve the used range in the worksheet. * Instead you could load the entire worksheet and get ranges for each row, * but this approach is *much* faster*/ Excel.Range range = worksheet.UsedRange; object[,] value = (object[,])range.get_Value(Excel.XlRangeValueDataType.xlRangeValueDefault); int rows = value.GetLength(0); for (int i = 1; i < = value.GetLength(0); i++) { dt.Rows.Add(); for (int j = 1; j <= value.GetLength(1); j++) { dt.Rows[dt.Rows.Count - 1][j - 1] = value[i, j]; } } //This line is very important. Otherwise you'll end up with N excel processes ExcelObj.Quit(); } dataGridView1.DataSource = dt; } } }
Hello world!
Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!