djelica Posted March 25, 2010 Share Posted March 25, 2010 Ok, i want to make site in php, which im not good at, but i will try to explain it with words and you just point me to right direction so i can bother myself coding and other stuff (way to improve my php skill). This site involves html and css also but it isn't problem because im good at it. This should be dead simple but its little bit hard to explain but please try to understand me and shouldn't be problem for you (php freaks) to get what i mean. The concept: Every unique visitor should get unique url to the site. So if the visitor come back to the site, the same url appears. (step 1) Lets say that a guy named Matt comes to my site. Somehow php generated url to the site will be given to him which will be recorded to MySQL DB for further details. Then Matt give that link to his friend John. When John visits the site, he gets new unique link to the site (then he can use that link to refer his friends, same as Matt did). So, because Matt referred one of his friends to the site (through url given at first step) his referral count increase by 1. Referral count should be increased in the DB. Pretty simple. got it ? So when someone refer 2 of his friends to the site (using their unique url) then script shows them additional content. and so on. I would set javascript to refresh page every 10 minutes, so referral count could be tracked live. I am newbie to php and mysql, i know only some simple functions, but im not dumbass who will ask deadly stupid questions because i know to use google for those, but i couldn't ask google about this one I need your help to get this done. Please assist me! I'm looking forward to this. for your easier understanding, i have attached image how it should look like. [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
andrewgauger Posted March 25, 2010 Share Posted March 25, 2010 get the ip address of the visitor: $ip=$_SERVER['REMOTE_ADDR']; convert the ip into a int: (credit: http://php.net/manual/en/language.types.integer.php) <blockquote> d_n at NOSPAM dot Loryx dot com 13-Aug-2007 12:33 Here are some tricks to convert from a "dotted" IP address to a LONG int, and backwards. This is very useful because accessing an IP addy in a database table is very much faster if it's stored as a BIGINT rather than in characters. IP to BIGINT: <?php $ipArr = explode('.',$_SERVER['REMOTE_ADDR']); $ip = $ipArr[0] * 0x1000000 + $ipArr[1] * 0x10000 + $ipArr[2] * 0x100 + $ipArr[3] ; ?> IP as BIGINT read from db back to dotted form: Keep in mind, PHP integer operators are INTEGER -- not long. Also, since there is no integer divide in PHP, we save a couple of S-L-O-W floor (<division>)'s by doing bitshifts. We must use floor(/) for $ipArr[0] because though $ipVal is stored as a long value, $ipVal >> 24 will operate on a truncated, integer value of $ipVal! $ipVint is, however, a nice integer, so we can enjoy the bitshifts. <?php $ipVal = $row['client_IP']; $ipArr = array(0 => floor( $ipVal / 0x1000000) ); $ipVint = $ipVal-($ipArr[0]*0x1000000); // for clarity $ipArr[1] = ($ipVint & 0xFF0000) >> 16; $ipArr[2] = ($ipVint & 0xFF00 ) >> 8; $ipArr[3] = $ipVint & 0xFF; $ipDotted = implode('.', $ipArr); ?> </blockquote> Query a mysql table for unique ips: $id = $_GET["id"]; $sql="SELECT ip from Visitors where referal=$id"; http://php.net/manual/en/book.mysql.php for how to use mysql in php don't forget to build a table (visitors) referal, visitors a table (referal) id, Name, etc Then insert the ip address into the table if it is unique: if in_array($ip, $sqlResultParsed){ $sql="INSERT into visitors (referal,ip) values ($id,$ip)"; } then you just need to check the count($sqlResultParsed) for how many referrals. Oh and you should look into using AJAX in lieu of 10 minute refreshes because AJAX is soooo cool. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.