Jump to content

l0gic

Members
  • Posts

    110
  • Joined

  • Last visited

Everything posted by l0gic

  1. l0gic

    Age

    Can you please put this at the top of that code and post the results: echo $_POST['month'] . " - " . $_POST['day'] . " - " . $_POST['year']; die();
  2. Have a squizz at this. <?php $server = ""; // Enter your MYSQL server name/address between quotes $username = ""; // Your MYSQL username between quotes $password = ""; // Your MYSQL password between quotes $database = ""; // Your MYSQL database between quotes $con = mysql_connect($server, $username, $password); // Connect to the database if(!$con) { die('Could not connect: ' . mysql_error()); } // If connection failed, stop and display error mysql_select_db($database, $con); // Select database to use $result = mysql_query("SELECT * FROM tablename"); // Query database while($row = mysql_fetch_array($result)) { // Loop through results echo "<b>" . $row['id'] . "</b><br>\n"; // Where 'id' is the column/field title in the database echo $row['location'] . "<br>\n"; // Where 'location' is the column/field title in the database echo $row['property_type'] . "<br>\n"; // as above echo $row['number_of_bedrooms'] . "<br>\n"; // .. echo $row['purchase_type'] . "<br>\n"; // .. echo $row['price_range'] . "<br>\n"; // .. } mysql_close($con); // Close the connection to the database after results, not before. ?> Also you should use underscores "_" rather than dashes/hyphens "-" when naming a variable.
  3. I really think the long way around has been taken here.. A cron-job is overkill, as is the code on each page load. The means to track online status has already been explained earlier in the thread. Personally, this is how I would do it. User logs in: $_SESSION['logged_in']=true; $_SESSION['user_id']=1; $_SESSION['user_name']="Bob"; ..and any other session variables you'd want to set. Now I have logged_in as a session variable, what would be the point of duplicating that logged_in value in a database when it's only going to remain true while the session is active/open. There really isn't one, I'd rather store the last_active time in the database because we can manipulate that much easier to suit out needs.. Database - Users Table (You'll have more fields than this but we're only ineterested in these few for now) user_id user_name last_active 1 Bob 1331149677 2 Joe 1331153547 3 Sam 1331156466 4 Tim 1331153320 5 Dan 1331161333 From that you already have all the information you need to find out if a user is online or active. i.e. if( last_active > time()-300 ) { user has been active within the last 300 seconds (five minutes) } And the last_active field would simply be updated with time() whenever they load or refresh a page.. UPDATE users SET last_active=time() WHERE user_id=$_SESSION['user_id'] AND username='$_SESSION['user_name']' ..with the user_id and user_name being a session variable that was set when the user logged in. Now whenever your user loads a page the session remains active, so $_SESSION['logged_in'] remains true and their last_active time gets set to the current time with time() and that's all the information we need to capture for this aspect of the project. Which makes displaying online or active users VERY easy on any of our other pages, for example seeing who is online in the list of comments about an article, and lets say its an article with the id of 333 in your database and your comments table shares a structure like this comment_id article_id user_id comment date_posted cooment_id is the unique identifier article_id is the article to which the comment was posted on user_id is the user id of the user that posted the comment comment is the comment date_posted is the date the comment was posted $comments = mysql_query("SELECT user_id, comment, date_posted FROM comments WHERE article_id=333"); while($comments_row = mysql_fetch_array($comments )) { $user_row = mysql_fetch_assoc(mysql_query("SELECT user_name, last_active FROM users WHERE user_id = $comments_row['user_id']")); if($user_row['last_active'] > time()-300) { $user_status = "Online"; } else { $user_status = "Offline"; } echo $user_row['user_name'] . "(". $user_status . ") said: " . $comments_row['comment'] . " on . " $comments_row['date_posted']; } You can easily change $user_status = "Online" to a green circle image or whatever, same with the offline. Hopefully this helps.. It may not be copy/paste/working as I didn't do any of this on my dev machine and I haven't even had my first coffee of the day but it should give you an understanding of how simple this should be to implement. Bascially the session variable for logged_on, the only thing you should be using that for is so that you know the user is logged on and can have access to certain data or features of the site, if they close the window or their session times out, it's not your problem. They'll just have to log in again. Well, I hope it makes sense anyway. You have all you need to know to get this working, and the only future questions I can imagine would be comparative to.. "How do I turn my Horse into a Unicorn?" (In english: How do I make something that can't do 'this'.. Do 'this'?) With the answer being along the lines of, "It doesn't work like that."
  4. Save your server some time and validate your form with JavaScript?
  5. Just as INT. You could do it without, you just wouldn't be able to 'update' anything until the user refreshed or requested another page. Now I think about it some more, I don't think I'd really use a 'logged_in' field in the database for that very reason, you'd only really get tto change it is the user used the log-out feature/link.. I'd stick to the database having 'last_activity' and use a session variable for 'logged_in'. I'd also try to use true/false rather than 1/0, but it doesn't really matter there I guess.
  6. Sorry when I said now() earlier, I actually meant time(). Anyway, sounds like you're making pretty good headway. The jquery stuff is essentially a copy/paste job, make these two files and put them in the same directory and then run them. now.php <script src="http://code.jquery.com/jquery-latest.js"></script> <script> $(document).ready( function() { $("#updatecontainer").load("updateonline.php"); var refreshId = setInterval(function() { $("#updatecontainer").load("updateonline.php"); }, 5000); // The '5000' here is the time in miliseconds 5000 = 5 seconds, etc. $.ajaxSetup({ cache: false }); } ); </script> <div id="updatecontainer"> In five seconds this will start updating every five seconds. But you wont see any of this text and if you don't echo the SQL in updateonline.php then you wont see any text at all! </div> updateonline.php <?php // Connect to your database server. // $con = mysql_connect("localhost","user","pass"); // Select your database. // mysql_select_db("my_db", $con); // Build your SQL update string. $sql = "UPDATE table SET lastactive = " . time() . " WHERE id = ?"; // Echo out your update string (remove this from final product). echo $sql; // Run your SQL update. // mysql_query($sql); // Close your database connection. // mysql_close($con); ?> If you watch it for 30 seconds or so you'll soon see what's happening, the SQL string is updating without the page refreshing and without you (the user) having to do anything. So aslong as the now.php page is open you can update your database to say they're online. I wouldn't run it every five seconds though, that's just a short time to show you how it works. The second thing you'll see is why I prefer to use time() instead of any other time or date format, and why I store it in a regular INT field in my database. You don't need to know time zones or anything when measuring time like this and it makes it very basic maths. As an example say I logged in at 1330935125 and my last activity update was at 1330935160 you can easily do this: 1330935160 - 1330935125 = 35 So I was online for 35 seconds, easy as! So then you could figure out your online people by looping through them and marking them as online if ( time() - lastactivity < 300 ) { user is online }else { user is offline } You could include the updateonline.php OR code from now.php (above) on every page of your site except the log out page and your database will stay up to date. Including them both on one page would have it run updates twice per page load, which we don't want creating extra stress on your server. I hope this helps anyway?
  7. As I posted above, and working in something like this http://www.brightcherry.co.uk/scribbles/jquery-auto-refresh-div-every-x-seconds/ to update the database while the user is still on the page but idle. All you need is now in this thread. - Online and Active: Compare database lastactivity to now(), if it's less than five (or however many minutes) difference then they're online - Online but Idle: Compare database lastactivity to now(), and work in the jquery-type of stuff the link above, set it too 300 seconds for five minute 'checks' - Online and Active: Again compare database lastactivity to now(), if last activity is longer than five minutes ago then they're offline Now the learning part, make it happen! Get some code together and see if you can get it working, if not come back with the code you're using and we'll see what we can do. P.S. Personally I'd store the time as now() (a unix timestamp, a count of seconds, more recent times will always be a higher number) in the database in an INT field then use basic maths to sort it out, no need for time zones or anything.
  8. Are you on a Windows or Linux/Unix based server? Windows: $png_path = '..\..\..\users\user_avatars\' Linux/Unix: $png_path = '../../../users/user_avatars/'
  9. Along these lines, but store the information in a database rather than a session variable. As when you have a 'lastActivity' field in your users table you can then loop through all of your users and check when they were last online or not. <?php ... $result = mysql_query("SELECT * FROM users"); while($row = mysql_fetch_array($result)) { if($row['lastActivity']+300 < now()) { // if lastActivity plus five minutes was longer ago then now echo $row['userName'] . " is online<br>"; // Green light }else { echo $row['userName'] . " is offline<br>"; // Red light } } ... ?>
  10. No problem, make sure you understand those functions though. There is information and examples on both here: http://php.net/manual/en/function.htmlentities.php http://php.net/manual/en/function.htmlspecialchars.php
  11. I believe it should be: $dateID = $_REQUEST['teetimedate'];
  12. l0gic

    totals

    Hmmn, I eyeballed through it all. But I'm not on my dev machine right now. I'll try and have another look when I get home, otherwise, keep playing with it you could get lucky!
  13. Ok, now we're getting somewhere! I'd like to introduce you to your new best friend htmlentities(), you would use it when inserting the thread title/body/etc into your database. <?php $str = "A 'quote' is <b>bold</b>"; // Outputs: A 'quote' is <b>bold</b> echo htmlentities($str); // Outputs: A 'quote' is <b>bold</b> echo htmlentities($str, ENT_QUOTES); ?> If you copy and paste either of those into an HTML page you'll see it converts < to < and so on. Also.. <?php $thread_body =\" . $_POST['thread_body'] . "\"; ?> is doing it wrong, you only need to use <?php $thread_body = $_POST['thread_body']; ?> You would only need to use quotes there when assigning a string to the variable, like.. <?php $thread_body = "This is my thread body!"; ?> Edit: You could also use htmlspecialchars()
  14. Using a back-slash will 'escape' these characters. $string = "It's not \"that\" bad!";
  15. l0gic

    totals

    Ok then maybe it's seeing one of the variebles as a string? Try: </php ... $left = inval($total) - intval($amount123); ... ?>
  16. Exactly what Danny said above. If I had to guess though it's not your [ making things go crazy.. Lets play spot the difference? $some_variable = "[" $some_variable = "["; Posting your code would help a lot.
  17. Have you thought about using a session variable instead? Have a look: http://www.php.net/manual/en/session.examples.basic.php
  18. I'll jump the gun and bet it's the same issue I used to have. I got around it by changing the "From:" header to "mydomain@myhost.com" (the actual account sending the email) and adding a "Reply-To:" header for "someone@mydomain.com" (the address you want people to reply to) If not set like this and if the originating domain "myhost.com" and the "From" header domain "mydomain.com" do not match, I imagine the spam filters will mark it as spam. It should look kinda like this.. <?php $header .= "Reply-To: Some One <someone@mydomain.com>\n"; $header .= "Return-Path: Some One <someone@mydomain.com>\n"; $header .= "From: Some One <mydomain@myhost.com>\n"; $header .= "Organization: My Organization\n"; $header .= "Content-Type: text/plain\n"; mail("to@wherever.com", "Message Subject", "This is my message.", $header); ?> Edit: Fixed typo.
  19. l0gic

    totals

    And you're sure that $_POST['total'] is coming through? try echo'ing it out and make sure it is. Because if it's not your $total has no value. <?php ... if(isset($_POST['total'])) { $total = $_POST['total']; echo "Looks like POST['total'] is set and \$total is now: $total"; die(); }else { echo "Turns out POST['total'] isn't set or the post was lost in the mail." die(); } ... ?> Pop that in and see what happens?
  20. Jackr, care to post the code you're using at the moment and see if we can help or point you in the right direction? At the moment your post is a bit like me going to an auto-store and asking, "My car needs a new head gasket, can I have one please?" Without letting them know what car model, make or year of car I drive.
  21. l0gic

    totals

    Is that your whole script/page? Because $total doesn't seem to be defined and/or set anywhere. If it's not, can you post it so we can better understand?
  22. I'd have to say yes, considering his two threads so far. Both of which I'm pretty sure are examples on php.net anyway.
  23. I think you want to use implode()? implode(separator,array) More: http://php.net/manual/en/function.implode.php Sorry didn't read that right! Use a loop to loop through both arrays and update your multi-dimensional one, something like. <?php $i=0; while($i < count($styles)) { $styles[$i][3] = $stylesbought[$i]; $i++; } ?> Above code may not be exact, not on my dev machine right now but hope you can see what I'm trying to do there?
  24. Correct, it used to seem weird to me too back in the day. I think it's because they call it session_start() rather than session_open() or session_continue() and your mind assumes the 'start' part is going to start a whole new session every time you use it. But no, it just lets the server know that you want to be able to access the session variables through that page.
  25. Ok, so you have a way of passing all the details from each PC to your database, that helps a lot. I would also include the date and time that the information is submitted. When you have that setup it's just a case of putting the right stuff in the right place and using it creatively. You'll then have a database with a collection of IP addresses as reported back by each PC and the date and time that the information was supplied. So have a list of IP addresses that are assigned and the last time they were used, which would be a pretty good indication that they're assigned. The date and time is handy because if that IP address hasn't been used for like a month then it gives you something to investigate and maybe even an IP address to re-assign to a new machine. I think though you may be over complicating it a tad. If I were you and was trying to do this, and each PC would report it's information to say a PHP script on your server that will insert or update records in your database then I'd just make an extra table in the database call it what you will, 'ip_list' or something. ip_address | assigned | last_use 192.168.0.1 | true | February 28, 2012 192.168.0.2 | true | February 28, 2012 192.168.0.3 | false | none 192.168.0.4 | false | none Obviously you'd fill this out with a script and not by hand.. And could add more fields as it suits. <?php // WARNING: I'd only run this once! $i = 1; while($i < 255) { $ip = "192.168.0.".$i; $sql = "INSERT INTO ip_list (ip_address, assigned, last_use) VALUES ('$ip', 'false', 'none')" // And the rest to run the query, etc. $i++; } ?> Then a simple bit of SQL can find you all the assigned IP address, loop through them to see if they're online or offline. $sql = "SELECT ip_adress, assigned, last_use FROM ip_list WHERE assigned='true'"; ..and another query can return you IP address that aren't assigned.. $sql = "SELECT ip_adress, assigned, last_use FROM ip_list WHERE assigned='false' LIMIT 10"; I'd use a LIMIT so you don't get a wall of IPs crit you for over nine thousand damage, limit can be set as a variable too. Can you see where I'm heading with this? It sounds like you have all the tools to put this in place and the scripts running on each PC would keep the ip_list table as up to date as I'd imagine you'd need.
×
×
  • 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.