Jump to content

l0gic

Members
  • Posts

    110
  • Joined

  • Last visited

Everything posted by l0gic

  1. Yeah I don't think you're going to be able to achieve what you're trying to do with just a PHP script alone. The only way I can see this working is if you manually collect all IP addresses for each PC/Device and store them in a database and use that as a point of reference when it comes to availbility. Or, have each PC/Device run a script or call of some kind when they start-up to enter or update their IP in the database. You could use each devices MAC address as an identifier for this also. And then use the above PHP to check if each IP is active or not by pinging it. Can you explain in anymore detail exactly what you're trying to do and how the network it will be running on is set up? Is each device manually configured to connect to the network, does DHCP come into play? Almost seems like it would be easier to scrape the data from your router/network hardware.
  2. Try using: $result=mysql_query($sql) or die(mysql_error());
  3. Make that.. <?php // Set the IP you want to ping here $ip = "10.1.1.1"; // Run the ping to the IP exec ("ping -n 1 -w 1 $ip", $ping_output); // Loop through the returned lines from the output $i=0; while($i < count($ping_output)) { echo "Line $i: " . $ping_output[$i] . "<br>"; $i++; } ?> And on my box it's Line 2 we want to look at so this: <?php // Set the IP you want to ping here $ip = "10.1.1.99"; // Run the ping to the IP exec ("ping -n 1 -w 1 $ip", $ping_output); if(preg_match("/Reply/i", $ping_output[2])) { echo "$ip replied, so it must be active!"; }else { echo "$ip did not reply so it may not be assigned?"; } ?> ..should work.
  4. I'm not 100% sure what you mean here, "vacant or unassigned" = the same thing? Vacant (adjective) 1. having no contents; empty; void: a vacant niche. 2. having no occupant; unoccupied: no vacant seats on this train. 3. not in use: a vacant room. Unassigned (adjective) 1. unassigned; not assigned. .. but this may help? <?php // Set the IP you want to ping here $ip = ??; // Run the ping to the IP exec ("ping -n 1 -w 1 $ip", $ping_output); // Loop through the returned lines from the output $i=0; while($i < count($ping_output)) { echo "Line $i: " . $ping_line . "<br>"; $i++; } ?> Take note of the line that will either say "Reply from *ipaddress*: bytes=.." or "Request timed out." then you can call that with $ping_output[0] (where 0 is the line number) and pop that in a conditional like: <?php .. if(strpos($ping_output[0],"Reply")) { echo "$ip replied, so it must be active!"; }else { echo "$ip did not reply so it may not be assigned?"; } .. ?> Then ditch the loop and mash it all together? Yes / No Note: Exact code may not work, not on my dev machine atm.
  5. Far from a God fella, I learnt a lot about PHP from the guys on these forums. And this method was kind of already mentioned earlier in the thread but I was just the first to put it into working code.. But you're wlecome. I was thinking about doing that, but tried to make it as simple to understand as I could. I'm pretty sure a more experienced hand could shrink it down to about five or six lines though, depending on how many results he wants to add.
  6. Shouldn't be too hard! Try: <?php // Create an array containing the score values you want to run $score = array(0.10, 0.30); // Great, that's an array! We could call any of the array values by using // $score[*] where * is its place in the array. // So... // $score[0] = 0.10 // $score[1] = 0.30 // Now we want to loop through this array and modify the // current score, turn it into your result and echo it $i=0; // Set out loop count to 0. while($i < count($score)) { // While our loop count is less then the number of values in the array, loop! if($score[$i] < 0.20) { // If $score[$i] (the first array value) is less than 0.20 then.. $score[$i] = 0.75; // ..set $score[$i] to the desired result (in this case 0.75) }else if($score[$i] < 0.40) { // Else if it's less than 0.40.. $score[$i]= 0.80; // ..set $score[$i] to the desired result (in this case 0.80) } echo $score[$i]."<br>"; // Echo $score[$i] and a line break. $i++; // Increment our loop count by one. } ?> That'll output: 0.75 0.8 You can add more 'scores' by adding them into the array at the start, example: <?php ... $score = array(0.10, 0.30, 0.13, 0.16, 0.25, 0.33); ... ?> And you can add more 'results' by adding more else ifs, example: <?php ... else if($score[$i] < 0.40) { $score[$i]= 0.80; }else if($score[$i] < 0.60) { $score[$i]= 0.85; }else if($score[$i] < 0.80) { $score[$i]= 0.90; } ... ?> Hope that helps?
  7. I'm a little confused, but I'm pretty sure the code you're looking for is pretty much exactly what you have pasted in your first post? It would need a bit of tweaking, but from what you've provided there that's about as much as I can tell you.
  8. I know this is a bit of a thread necro, but I saw this while looking for something else and thought it couldn't be too hard to work with. Anyway, I came up with this: <?php $horitiles = 5; // how many tiles wide $verttiles = 5; // how many tiles high $v = 0; $h = 0; $maxmovesize = 1; // hos many tiles can you move per-move (not perfect though, change it to 2 or 3 and see) // there is treasure in the map for you to find, you can find it easy by looking at the querystring // if theres no querystring setting treasure it'll be at tile 2,2 if(isset($_REQUEST['th']) && isset($_REQUEST['tv'])) { $treasureh = $_REQUEST['th']; $treasurev = $_REQUEST['tv']; }else { $treasureh = 2; $treasurev = 2; } // current position, default if nothing in querystring is 1,1 if(isset($_REQUEST['v'])) { $currentv = $_REQUEST['v']; }else { $currentv = 1; } if(isset($_REQUEST['h'])) { $currenth = $_REQUEST['h']; }else { $currenth = 1; } echo "<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\">"; while($v < $verttiles) { echo "<tr>"; while($h< $horitiles) { if($v == $currentv && $h == $currenth) { if($h == $treasureh && $v ==$treasurev) { echo "<td><img src=\"tile-treasure.jpg\"></td>"; $treasure = "You found the treasure!<br>"; $treasureh = rand(1,$horitiles)-1; $treasurev = rand(1,$verttiles)-1; $link="<a href=\"map.php?h=$h&v=$v&th=$treasureh&tv=$treasurev\">Reset!</a>"; }else { echo "<td><img src=\"tile-on.jpg\"></td>"; $treasure = ""; $link=""; } }else { $gol = $currenth-$maxmovesize; $gor = $currenth+$maxmovesize; $gou = $currentv-$maxmovesize; $god = $currentv+$maxmovesize; if($h >= $gol && $h <= $gol+$maxmovesize && $v == $currentv || $h >= $gol && $h <= $gol+$maxmovesize && $v == $currentv+1 || $h >= $gol && $h <= $gol+$maxmovesize && $v == $currentv-1 || $h <= $gor && $h >= $gol+$maxmovesize && $v == $currentv || $h <= $gor && $h >= $gor-$maxmovesize && $v == $currentv+1 || $h <= $gor && $h >= $gor-$maxmovesize && $v == $currentv-1) { echo "<td><a href=\"map.php?h=$h&v=$v&th=$treasureh&tv=$treasurev\"><img src=\"tile-move.jpg\" border=\"0\"></a></td>"; }else if($v >= $gou && $v <= $gou+$maxmovesize && $h == $currenth || $v >= $gou && $v <= $gou+$maxmovesize && $h == $currenth+1 || $v >= $gou && $v <= $gou+$maxmovesize && $h == $currenth-1 || $v <= $god && $v >= $god-$maxmovesize && $h == $currenth || $v <= $god && $v >= $god-$maxmovesize && $h == $currenth+1 || $v <= $god && $v >= $god-$maxmovesize && $h == $currenth-1) { echo "<td><a href=\"map.php?h=$h&v=$v&th=$treasureh&tv=$treasurev\"><img src=\"tile-move.jpg\" border=\"0\"></a></td>"; }else { echo "<td><img src=\"tile.jpg\"></td>"; } } $h++; } $h = 0; echo "</tr>"; $v++; } echo "</table>"; echo "<br>"; echo $treasure."<br>"; echo $link; ?> I've attached the images I've used as tiles 32x32 icon size. This is a very simple take on it and some code is redundent, would've used a database but didn't have access to one on the machine I was using. Though it could easily be converted to use a database (and even have multiplayer support over a larger 'map'). Something fun to play with, was a lot of fun to make as I've been out of PHP for about 12 months and am starting my return at the moment! Could be done a lot better, but hey, it's an idea.
  9. Developing on a Windows machine and thought there may be another way. But have talked to a couple of people and have decided to resurrect my LAMP box as it seems I should really be doing it the right way and not cutting corners. Option b could work, until the point that 100 users are online and refreshing pages 500 times a minute.. Would be better off running it once a minute as a cron job.
  10. Haven't done much in PHP for a while, and as a refresher and a bit of a challenge to myself I have decided to write up a simple game of sorts. Basically in the game I have townships, every play has their own town. And I want these towns to have events every 3-10 hours, and have these events have results such as births/deaths/fires/flooding/etc. At the moment I'm looking at this kind of setup: A database table with the city information.. city_id, city_owner_id, city_name, etc. I figure I can make another field such as city_nextevent and fill it with a timestamp plus a random number of seconds. then when the user views their city if city_nextevent is older than current time then run the event function and set the next event time. In my head this idea seems to work well, until I realised that if the user doesn't log on for 20+ hours the events will not stack, they will only get the one event when they next view their town when several events should have passed. I realise I could use a cronjob to check all events across all towns, but is there a better way of doing it. I had also though about adding several fields to the database containing say the next five event times, then updating each field after time had passed. Which gives more events if the user has been offline for 20+ hours. So if the play was offline for say a week, their town would pretty much dry up until they returned. Basically, I want their town to run while they're offline. But was trying to avoid using a cronjob. Anyone have any thoughts on how this could be done?
  11. You could also prioritize items that have been viewed multiple times so like above with the session variable, but instead of true/false have it count the number of times it's been viewed. I know personally I usually look at something and come back to it again several times before I buy online. You could order from most viewed to least viewed and call it something like, "Other items you've recently been interested in."
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.