Jump to content

premiso

Members
  • Posts

    6,951
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by premiso

  1. In your database have a timestamp, lastchecked (something like that). Each time the user hits the page, set this timestamp to the current time. To set them as being timed out you would probably need a cron job to run every x minutes that checks the timestamp in this table, and if lastchecked + 5 < current time then set a field as them being inactive. If you want to also keep track of how long they have been on the site you may want a structure like so: DB Fields - lastchecked - timeentered - totaltime When they first enter the site (timeentered should be null) set lastchecked. If timeentered is not null just updated last checked (since the cron job runs every minute or 2 like it should this should update itself properly). In the cron job you would need to do the check, if lastchecked + 5 < current time grab timentered and subtract lastchecked - timeentered, this will give you the total number of seconds the user was on the site, now update the database, set timeentered equaled to null and add the total number of seconds for this session to the totaltime field. This will get you within +- x minutes the total time the user was on the site. I use +5 above that is assuming x minutes is 5 minutes. That is the logic for it, if you want code examples I would google, "Whos Online PHP Script" and you should find many examples of similiar setups (they may not use cron jobs but cron jobs will ensure the +- 5minute rate, without the cron job you cannot be sure, cause they could have been off for 30 minutes and if no one hit the site to reset the timeentered it would show them as being on that whole time).
  2. Impossible. Reasoning is that the user can just close the browser and the browser does not care to send a signal to your site or their site. <body onUnload="" would work as long as they actively left your site view a link or back (I think back/forward to) buttons. But if they typed in the URL manually, I do not think this would work. Unfortunately that part of the request, is impossible to do. You can however set a timeout, after x minutes of no response set them as being out of the site, if they ping the image again within x minutes reset the time stamp to be x more minutes etc.
  3. json_encode That would be the best way. I would also recommend using jQuery (do a google for it). It makes AJAX a ton easier to do, and has examples!
  4. array_push array_push($_SESSION['array'], "item")
  5. Create a "image file" that displays a blank white space. Have the user call to it by <img src="http://yoursite.com/img.php"> Inside the img.php file add the code to log data to the database, then spit out a blank image using the image create functions. Should work like you want it without having a nasty iframe and the user does not know it is happening. The user can even set the style.display property on the image to none and yea. <img src="http://yoursite.com/img.php" style="display: none;"> Then it is not even viewable period, but you still get the data logged.
  6. As long as he has all the fields in the VALUES, he does not need to specify them. Corrected version: <?php include 'config.php'; include 'functions.php'; mysql_select_db('exembar_site'); // added && instead of & if( ($_POST['username'] != "") && ($_POST['password'] != "") && ($_POST['location'] != "") && ($_POST['realname'] != "") && ($_POST['email'] != "")) { $username = $_POST['username']; $password = $_POST['password']; $location = $_POST['location']; $realname = $_POST['realname']; $email = $_POST['email']; //sanitize everything $username = sanitize($username); $password = sanitize($password); $location = sanitize($location); $realname = sanitize($realname); $email = sanitize($email); $sql = "INSERT INTO `staff` VALUES('','$username','$password')"; // removed { and } mysql_query($sql) or die(mysql_error()); $sql = "SELECT * FROM `staff` WHERE `username`='$username' AND `password`='$password'"; // removed { and } echo $sql; $res = mysql_query($sql) or die(mysql_error()); $info = mysql_fetch_array($res); // removed $ here. //$id = info['id']; $sql = "INSERT INTO `staff_info` VALUES('','$location','$realname','$email','$id')"; // removed the { and } from here { and } are only needed for ' not " //header("location:{$root}"); } else { echo "There can be no empty fields!<br>If something is unknown, type 'UNKNOWN'."; } ?> Give that a try and see if you still get the parse error.
  7. <?php session_start(); //required before any output on each page you wish to use sessions. $_SESSION['arrayData'] = array("test", "test2"); foreach ($_SESSION['arrayData'] as $data) { echo $data . "<br />"; } ?>
  8. Ummm... while( $row = mysql_fetch_assoc( $res ) ) 18. { 19. $qry = "select LinkIndex from Links where CustomerNum = ".$custId." and LinkOrder = ".$newOrder; 20. $res2 = mysql_query( $qry, $conn ); 21. if( $res2 ) 22. { 23. while( $row2 = mysql_fetch_assoc( $res2 ) ) 24. { Would be: foreach ($pdo->query($qry as $row) ){ $qry2 = "select LinkIndex from Links where CustomerNum = ".$custId." and LinkOrder = ".$newOrder; foreach ($pdo->query($qry2) as $row2) { } } etc etc
  9. It should be, from that it should work exactly as you described. Are there any errors? Try adding this to index.php and see what happens: index.php ini_set("display_errors", 1); error_reporting(E_ALL); include('/path/to/file/header.php'); html html html html include('/path/to/file/ads.php'); html html html include('/path/to/file/footer.php');
  10. Below replaces lines 14-17. foreach ($pdo->query($qry) ) You need to initiate the pdo connection at the top of the file or in the db include file like: $pdo = new PDO(DSN_STRING_NEEDED_HERE, "dbusername", "dbpassword"); The above would replace the mysql_connect and mysql_select_db http://us2.php.net/manual/en/pdo.construct.php see that for more information on the DSN and pdo for more information on each function etc.
  11. Describe what you mean when you say "different section". A different domain name or just a different directory IE: beachhostel.nl/newdirectory/newfile instead of beachhostel.nl/blog/rss
  12. Post some code where this is happening, the form and the page the form loads into (the specific parts if possible)
  13. Alright instead of doing a third edit I decided to post a possible answer for the young tyke, since he does not understand that smarty offered a way to set the template_directory without having to modify the original code. # define('SMARTY_PHP_PASSTHRU', 0); # define('SMARTY_PHP_QUOTE', 1); # define('SMARTY_PHP_REMOVE', 2); # define('SMARTY_PHP_ALLOW', 3); define('SMARTY_MY_TEMPLATE', $template); # # /** # * @package Smarty # */ # class Smarty # { # /**#@+ # * Smarty Configuration Section # */ # # /** # * The name of the directory where templates are located. # * # * @var string # */ # var $template_dir = "templates/" . SMARTY_MY_TEMPLATE; # That would solve your problem. But take my advice above and use the proper methods, cause if smarty comes out with a huge vunerability, you have to modify all that code again and remember what you did.
  14. <?php include(smartyclasshere); $smarty = new Smarty; $smarty->template_dir = "templates/$template"; ?> That should get you the desired results. EDIT: decided to explain. Once a class has been instantiated and it has a var of $x then you can assign any variable to $x by calling instantiated class (in this case $smarty) using the ->x. Using that you can read the variable or set the variable. The variable is a "property" of the smarty class with read/write access to it. So if smarty had a var $x defined in the class, this would be the call to change it: <?php include(smartyclasshere); $smarty = new Smarty; $smarty->x = "bob"; echo $smarty->x; // should print bob (if $x was defined in the class chances are it wasnt but yea this is just demonstration purposes. ?> EDIT EDIT: Seeing that you are attempting to modify the class for no reason, I decided to help you understand something. I would not change the smarty class period, it works fine as it is as long as you invoke the right methods. I would revert back to the original version and use the above code to change the directory, as that is essentially what you want to do right? If you do not want to change the directories (which I gathered is all you wanted to do from the initial post) then please restate your question exactly and clearly.
  15. http://www.wampserver.com/en/ Install a wamp server, then you should be able to run php files and code. I would also look into a simple news system tutorial online.
  16. define Will set constants. See above for usage.
  17. I would look into: simple_xml in replace of fetch_rss
  18. You would need the third table to have a normalized database. To create the table you need to find what you need in the diagnoses table. You will at least need a diagnosesid, dos_id (to link to the billing table), diagnosis and any other information you need for a diagnoses. Then you just link the billing table to the diagnoses table with a query like: $sql = "SELECT * FROM dos, diagnosis WHERE dos.dos_id = diagnosis.dos_id AND dos.pt_id = '" . $_GET['id'] . "' order by dos.billing_date";
  19. You dont have session_start at the top of the script.
  20. Its a shortened if/else statement. If the field is equal to 0 set it to 0 else set it to $row['field'];
  21. Post your MySQL table structure. It seems you are calling the columns wrong.
  22. MySQL is in the title....but here is my version! <?php $result = mysql_query("SELECT field FROM tbl_name WHERE field = 1"); //replace tbl_name with your tbl if (mysql_num_rows($result) == 0) { echo 'Do this here'; }else { echo 'Do this other thing here!'; } ?> =)
  23. <?php //database inforamtion $host="stocks"; // Host name $username="wbennett"; // Mysql username $password="mysql5"; // Mysql password $db_name="wbennett"; // Database name $tbl_name1="flight_webair"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $flight_route_out=isset($$_POST['flight_route_out'])?$_POST['flight_route_out']:null; $flight_route_return=isset($_POST['flight_route_return'])?$_POST['flight_route_return']:null; $date_out=isset($_POST['departure_date'])?$_POST['departure_date']:null; $date_return=isset($_POST['return_date'])?$_POST['return_date']:null; $passenger_num=isset($_POST['num_of_pass'])?$_POST['num_of_pass']:null; $one_way= isset($_POST['one_way'])?$_POST['one_way']:null; // make sure value is available first. //To protect MySQL injection $flight_route_out = stripslashes($flight_route_out); $flight_route_return = stripslashes($flight_route_return); $flight_route_out = mysql_real_escape_string($flight_route_out); $flight_route_return = mysql_real_escape_string($flight_route_return); //Queries $sql1="SELECT * FROM `$tbl_name1` WHERE `flight_route` = '$flight_route_out'"; //$sql="SELECT * FROM $tbl_name1 WHERE flight_route_return='$flight_route_return'"; //Execute query 1 $result = mysql_query($sql1) or die(mysql_error()); echo mysql_num_rows($result); while ($row = mysql_fetch_assoc($result)) { echo $row['flight_route_out']; // removed the $ echo $row['flight_route_return']; // removed the $ } mysql_free_result($result); ?> Should solve the undefined index (those are not fatal errors but you should check if a variables exists before assigning it.)
  24. if ($_SESSION['Money'] > 14){ $sql = "UPDATE users SET Money=Money-15 WHERE id=".$_SESSION['user_id'].""; $sql2 = "UPDATE users SET badge1=1 where id=".$_SESSION['user_id'].""; $result = mysql_query($sql) or die (mysql_error()); $result2 = mysql_query($sql2) or die (mysql_error()); // now set session variables $_SESSION['Money'] = $_SESSION['Money'] - 15; $_SESSION['badge'] = 1; You are only updating the database.
  25. You keep removing important peices, lol. <?php ini_set("display_errors", 1); error_reporting(E_ALL); //database inforamtion $host="stocks"; // Host name $username="wbennett"; // Mysql username $password="mysql5"; // Mysql password $db_name="wbennett"; // Database name $tbl_name1="flight_webair"; mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $flight_route_out=$_POST['flight_route_out']; $flight_route_return=$_POST['flight_route_return']; $date_out=$_POST['departure_date']; $date_return=$_POST['return_date']; $passenger_num=$_POST['num_of_pass']; $one_way= isset($_POST['one_way'])?$_POST['one_way']:null; // make sure value is available first. //To protect MySQL injection $flight_route_out = stripslashes($flight_route_out); $flight_route_return = stripslashes($flight_route_return); $flight_route_out = mysql_real_escape_string($flight_route_out); $flight_route_return = mysql_real_escape_string($flight_route_return); //Queries $sql1="SELECT * FROM `$tbl_name1` WHERE `flight_route` = '$flight_route_out'"; //$sql="SELECT * FROM $tbl_name1 WHERE flight_route_return='$flight_route_return'"; //Execute query 1 $result = mysql_query($sql1) or die(mysql_error()); echo mysql_num_rows($result); while ($row = mysql_fetch_assoc($result)) { echo $row['flight_route_out']; // removed the $ echo $row['flight_route_return']; // removed the $ } mysql_free_result($result); ?> I added the variables be assigned from post back 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.