require 'config.php'; require 'inc/global.php'; $db = db_connect(); $link_id = mysql_real_escape_string($_GET['id'],$db); $query = "SELECT hits_in FROM ndlinks_affiliates WHERE link_id='$link_id' LIMIT 1"; $hits = mysql_fetch_array(mysql_query($query, $db)); $hits = $hits['hits_in'] + 1; $query = "UPDATE ndlinks_affiliates SET hits_in='$hits' WHERE link_id='$link_id' LIMIT 1"; mysql_query($query, $db); $ip = $_SERVER['REMOTE_ADDR']; $query = mysql_query("SELECT ip FROM ndlinks_affiliates WHERE link_id='$link_id' AND ip = '$ip'")or die(mysql_error()); if(!mysql_num_rows($query)) { mysql_query("UPDATE ndlinks_affiliates SET ip='$ip' WHERE link_id='$link_id'") or die(mysql_error()); }else{ $ip_data = mysql_fetch_array($query); $ips = $ip_data['ip'].$ip; mysql_query("UPDATE ndlinks_affiliates SET ip='$ips' WHERE link_id='$link_id'") or die(mysql_error()); } header("Location: {$conf['site']['url']}Merch/");
MySql - listing?
#21
Posted 27 August 2006 - 11:41 PM
#22
Posted 28 August 2006 - 10:28 PM
#23
Posted 29 August 2006 - 03:24 AM
#24
Posted 29 August 2006 - 05:27 AM
<?php $$id = $_GET['id']; $i = 0; $query = @mysql_query("SELECT * FROM `table` WHERE id = '$id' LIMIT 0,1") or die(mysql_error()); while( $row = mysql_fetch_array( $query ) ) { $ips = $row['ip']; $ipArray = unserialize( $ips ); foreach( $ipArray as $value ) { $i++; } if( $i > 0 ) { $x = 0; foreach( $ipArray as $value ) { $value[$x] = $value; $x++; } $value[$x++] = $_GET['ip']; $newArray = serialize( $value ); $query = @mysql_query("UPDATE `table` SET ip = '$newArray' WHERE id = '$id'") or die(mysql_error()); echo 'Ip added!'; } else { $query = @mysql_query("INSERT INTO `table` (`id`, `ip`) VALUES ('', '$ip')") or die(mysql_error()); echo 'Ip inserted!'; } } ?>
I'm sure someone les slazy can modify that into ndlinks (or have it seperate to save messing about with ndlinks) but this is just me with an idea (not tested)
Edited by .Matt, 29 August 2006 - 05:28 AM.
#25
Posted 29 August 2006 - 03:36 PM
You had just one small error in adding two '$' for a variable, but I'll edit it a tad for his script I guess.
I'll also just add a small type change just to make sure the id is an integer.
<?php $id = settype($_GET['id'], 'integer'); $i = 0; $ip = $_SERVER['REMOTE_ADDR']; $query = @mysql_query("SELECT * FROM `ndlinks_affiliates` WHERE id = '$id' LIMIT 0,1") or die(mysql_error()); while($row = mysql_fetch_array($query)){ $ips = $row['ip']; $ipArray = unserialize($ips); foreach($ipArray as $value) $i++; if($i > 0){ $x = 0; foreach($ipArray as $value){ $value[$x] = $value; $x++; } if(!in_array($ip, $value) $value[$x++] = $ip; $newArray = serialize($value); $query = @mysql_query("UPDATE `ndlinks_affiliates` SET ip = '$newArray' WHERE id = '$id'") or die(mysql_error()); echo 'Ip added!'; } else{ $query = @mysql_query("INSERT INTO `ndlinks_affiliates` (`id`, `ip`) VALUES (NULL, '$ip')") or die(mysql_error()); echo 'Ip inserted!'; } } ?>
Actually yours is better than mine would have been.
Oh wait a minute... you don't have squat about getting the IP.
I'll fix that up...
There, that work?
Just a thought, but you don't really need the incrementing $x variable do you? Just using '[]' will automatically stick it on the end of the array...
Edited by Demonslay, 29 August 2006 - 03:45 PM.
#26
Posted 29 August 2006 - 11:29 PM
$db = db_connect(); $link_id = mysql_real_escape_string($_GET['id'],$db); $query = "SELECT hits_in FROM ndlinks_affiliates WHERE link_id='$link_id' LIMIT 1"; $hits = mysql_fetch_array(mysql_query($query, $db)); $hits = $hits['hits_in'] + 1; $query = "UPDATE ndlinks_affiliates SET hits_in='$hits' WHERE link_id='$link_id' LIMIT 1"; mysql_query($query, $db); $id = settype($_GET['id'], 'integer'); $i = 0; $ip = $_SERVER['REMOTE_ADDR']; $query = @mysql_query("SELECT * FROM `ndlinks_affiliates` WHERE link_id = '$id' LIMIT 0,1") or die(mysql_error()); while($row = mysql_fetch_array($query)){ $ips = $row['ip']; $ipArray = unserialize($ips); foreach($ipArray as $value) $i++; if($i > 0){ $x = 0; foreach($ipArray as $value){ $value[$x] = $value; $x++; } Line 31: if(!in_array($ip, $value) $value[$x++] = $ip; $newArray = serialize($value); $query = @mysql_query("UPDATE `ndlinks_affiliates` SET ip = '$newArray' WHERE link_id = '$id'") or die(mysql_error()); echo 'Ip added!'; } else{ $query = @mysql_query("INSERT INTO `ndlinks_affiliates` (`link_id`, `ip`) VALUES (NULL, '$ip')") or die(mysql_error()); echo 'Ip inserted!'; } } header("Location: {$conf['site']['url']}Merch/");
By using the code I have above, I run the script and it gives me this in return.
Parse error: syntax error, unexpected T_VARIABLE in /home/faktionb/public_html/contest/in.php on line 31
I would fix it myself, however now you guys are talking about things I cant just bs my way out of.
Edited by Korndawg, 29 August 2006 - 11:30 PM.
#27
Posted 30 August 2006 - 04:44 AM
if(!in_array($ip, $value)) $value[$x++] = $ip;
#28
Posted 30 August 2006 - 03:51 PM
Maybe I should just work with a .txt file? Would that be harder? have it record the id (if it isnt already present) and beyond the | have the IP's listed separated by spaces? Or would that just give the same amount of problems as this is now?
#29
Posted 30 August 2006 - 03:55 PM
What do you mean by not working? It inserts nothing?
Edited by .Matt, 30 August 2006 - 03:56 PM.
#30
Posted 30 August 2006 - 03:59 PM
Korn... you should really just sit down and examine the code and wrap your head around it. Trust me, this is easy crap... just some simple functions and variable assigning in logical order...
And a textfile would be just the same, only ANYONE could view it if they knew the filename, whereas a database no one without permission (and the password, etc.) can view it.
Also, usually a database search is considerably faster than a file search, especially if it has to split every single row of every single line. You'd also have to split it somehow to include an id, since you can't have columns like in a database.
I honestly think you are making this too hard on yourself. Just do like I said and study to code. Never just take code from someone and assume it's 100%. Analyze it and fix it for your own needs and crap, it's easy enough to figure out if you have the basic PHP understanding...
Edited by Demonslay, 30 August 2006 - 04:00 PM.
#31
Posted 31 August 2006 - 03:06 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users