Welcome Guest, Not a member yet? Register   Sign In
CI_session table question
#1

[eluser]bogdan3l[/eluser]
CREATE TABLE IF NOT EXISTS `ci_sessions` (
session_id varchar(40) DEFAULT '0' NOT NULL,
ip_address varchar(16) DEFAULT '0' NOT NULL,
user_agent varchar(50) NOT NULL,
last_activity int(10) unsigned DEFAULT 0 NOT NULL,
user_data text NOT NULL,
PRIMARY KEY (session_id)
);

Could someone explain me why the ip_address is varchar(16) and not varchar(15) or int?

Thank you!
#2

[eluser]theprodigy[/eluser]
I can tell you why it's not int. Int's (and any number formats) require at most one decimal in the number. IP addresses have 3. Thus it is not in number format.

As for why it's 16 and not 15 characters, I can't tell you that. I'll leave that for someone who can make a better guess than me Wink
#3

[eluser]jedd[/eluser]
[quote author="theprodigy" date="1265177846"]I can tell you why it's not int. Int's (and any number formats) require at most one decimal in the number. IP addresses have 3. Thus it is not in number format.[/quote]

Hmm.

Integers have no decimal point at all - or rather, nothing to the right of the (implied, but not shown) decimal point.

IPv4 addresses have a standard integer representation - calculated quite easily by multiplying the first octet by 256^3, the second by 256^2, the third by 256 and adding the last. This is often used in database storage systems, for semi-obvious reasons.

I'm equally stumped on the 16 char specification, though. Of course if the extra char is blowing your capacity and performance specs out of the water, then you have some pretty streamlined code (and I'm quite envious).
#4

[eluser]bogdan3l[/eluser]
jedd, Smile, now that was a very nice replay. Thank you!
#5

[eluser]Muhamad Perdiyansyah[/eluser]
how to 3 session level..?
#6

[eluser]Michael Wales[/eluser]
I've always been curious about that as well - I can think of very few instances in which an IP should not be saved in its integer form. The string representation adds no value at all, it's just storage only - you can sort on it appropriately, it won't remove leading zeros appropriately, etc. INET_ATON() and INET_NTOA() take care of all of this for you.




Theme © iAndrew 2016 - Forum software by © MyBB