Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. Do you plan on ever using &addcomment=false? If not, then I would just stick with the isset() check and ignore what the value is. If you do think you'll be using a false value, then I would do the string comparison: $addcomment = (isset($_GET['addcomment']) && $_GET['addcomment']=='true'); Note that typecasting to a bool would not yield a true result because the string is 'true', but because it's not '' (empty) or '0' (zero). For instance, the following: $value = 'false'; $bool = (bool)$value; $bool would be true, not false. So if you do pass a 'true'/'false' you need to test them as a string, not just typecast. If you instead use '1'/'0' then you can typecast to either bool or int and it will work ok.
  2. Anytime you can't guarantee that a variable/index exists (usually with any of the $_* vars that comes in from the request) you should use isset() to prevent the notice error. Sometimes, just checking whether it is set is enough. If you set $_SESSION['loggedin'] when the user does their login, then unset it or destroy the session data on logout, then the mere fact that $_SESSION['loggedin'] exists is enough: if (isset($_SESSION['loggedin'])){ ... }
  3. And if the script takes a long time to process (or errors) your recursive function is going to annihilate your stack by making it grow too large, thus causing php to crash. No, the correct way to handle this is with a simple loop. Also, given the sleep(15) you'll be waiting 4 hours before you hit the $i > 1000 failsafe.
  4. If your seeing the PHP code instead of it being run, there are two likely causes for this: 1) Your using <? rather than <?php for your starting tag. <? is known as a short tag and is not valid unless enabled (it is not enabled by default I believe). You should always use <?php as it will always work. 2) Your server is not properly configured to parse PHP files. Fix number one first and then try. If you still have problems try re-installing your server. If you still have problems you'll have to post more details about your setup (os, server software, how you installed it, etc).
  5. Not really. There is no format code that will give you what you want, so you have to get the 1-12 version and subtract one. There's various ways you can accomplish that, all probably just as good as any other.
  6. I don't think it is necessary, however it has been a long time since I have used mysqli. I have been using PDO for the last couple years, and the equivalent is not necessary with that API. If it doesn't work, add it back, just after the mysqli_stmt_execute.
  7. // Execute query. if (mysqli_stmt_execute($stmt)){ // Bind result-set to variables. mysqli_stmt_bind_result($stmt, $articleID, $title, $description, $keywords, $heading, $subHeading, $publishedOn, $author, $body, $referenceListing, $endnoteListing); $articleExists = mysqli_stmt_fetch($stmt); if ($articleExists){ //whatever } } // Close prepared statement. mysqli_stmt_close($stmt); That should be sufficient. You want to check whether the query executed by checking the return value from mysqli_stmt_execute(). For determining if there was data in the query, rather than checking the number of rows, check whether the fetch was successful by the return value of mysqli_stmt_fetch. If the fetch was successful, your bound variables should all be set and you can use them where needed.
  8. If your using apache as a system service, then it won't be able to interact with the desktop (nor will anything launched via it). My guess is your program is crashing because it is assuming some system call worked which did not in this restricted environment. To fix it you'd have to allow apache to interact with the desktop. You do this in the group policy editor somewhere, but I am not sure where. Google can give you better instructions.
  9. You can wrap in in abs() to ensure it is positive. $diff is in # of seconds, so your statement is not going to work. It's also not correct, look at what I did above. The cycles is gathered via integer division. Since your interested in days, you'd be best served by converting $diff to days first. $days = $diff/(60*60*24); $cycle = intval($days / 26)+1; //26 days in your cycles. +1 to make it 1-14 rather than 0-13 The current day you get via the modulus operator which returns the remainder of a division operation $day = $diff % 26 + 1; //26 days in the cycle. +1 to make it 1-26 rather than 0-25 Modulus returns the number value past the last evenly divisible number. So say your $diff is 176 (days). 176/26 = 6.769 So we drop the decimals and multiple the integer with 26, to get 26*6 = 156 Then we take that and subtract it from 176, for: 176-156=20 So modulus will return 20. So for $diff=176 (days) we get: $cycle = intval(176/26)+1 = 7; $day = 176 % 26 + 1 = 21; So you are on cycle 7, day 21.
  10. Than a simple modulus and division? Not likely. Running loop method: Method ran in 1.3520817756653 seconds int(10) int(20) Running math method: Method ran in 0.061004877090454 seconds int(10) int(20) when performing 100,000 iterations.
  11. Perhaps this will help: <?php $ts = mktime(11, 11, 11, 11, 11, 2011); $dayOfYear = date('z', $ts); $cycle = intval($dayOfYear/26); $day = $dayOfYear % 26; echo '<h1>Cycle '.$cycle.'</h1>'; echo '<p>Day: '.$day.'</p>';
  12. Given your past posts, I think the word you want is passing, not parsing. Basically, here's the rundown of what you want to do near as i can tell: 1) Have your index.php print a form with a site select and a phone select. Name the phone select as an array, eg name="phones[]". When you change the site, use javascript to update the options in the phone select. 2) When you submit the page, check for the phones array and then run the command with the proper arguments. I'll assume the value of each of the phone options will be that phone's IP. If not you'll have to look it up. <?php if (isset($_POST['phones']) && is_array($_POST['phones'])){ //escape the arguments $ips = array_map('escapeshellarg', $_POST['phones']); //Run the command with the ip's as arguments exec('/usr/bin/php reboot.php '.implode(' ', $ips), $ret, $output); } 3) Update your reboot script to be able to reboot multiple phones by reading each ip from the command line. They are all available in $_SERVER['argv'][1] ... $_SERVER['argv'][n] $ips=array_slice($_SERVER['argv'], 1); foreach ($ips as $ip){ //reboot $ip; }
  13. Your if statement implies that $ModType is a number (2,3,4,..) however in your eval your using it as if it were a symbol (+,-,*,...)
  14. The screenshot add-ons for firefox will usually allow you to grab the entire page. Ex, Pixlr Grabber
  15. Change to: $this->container = new Config_Container('section', 'root');
  16. When you start a session, a unique ID is generated and assigned to that user by way of setting a cookie. The name of this cookie is set by the session_name() function, and defaults to PHPSESSID. Whenever the user visits a page, it's browser sends this cookie back to the server. When you call session_start, it first checks to see if this cookie value exists. If it does, it resumes that session by loading the data associated with that session out of a file. If no cookie value is sent then it starts a new session by generating an ID, as mentioned above. This cookie value is how you know which user is requesting the page. All this typically happens behind the scenes. You can customize the process if desired but usually you do not need to. You can pass the session id in the URL instead of as a cookie value, however this is not recommended as users may copy/paste a url to your site which contains the session id and send it to another person. This other person would then resume the first users session, even though they shouldn't. This is known as session hijacking. There are ways to prevent it (and you should even when using cookies) but by not passing the ID around in the url you go a long way toward preventing it. PHP cleans up the session data files periodically through a garbage collection process. When the data file is removed this way, the session is destroyed. You can also manually destroy it, such as on a logout page using session_destroy(). These configuration directives control this process: session.gc_probability session.gc_divisor session.gc_maxlifetime The gc_maxlifetime is the duration in seconds before the session is considered inactive and cleaned up. It defaults to about 20 minutes. When checking inactivity it compares the duration between when the session was last used and the current time. The last used time is the last time a request was sent using that session id. You don't really know if the session is timed out. It just disappears. If the user's session timed out, say from them going out to lunch, and php cleans up the session file, the next time they load a page it will be as if they are starting a brand new session.
  17. Probably the best you could do with your query is using something like: ORDER BY INSTR(nom, 'plan')
  18. JOIN syntax FROM kill4silence_photos_albums album LEFT JOIN kill4silence_photos_photos photos ON album.id=photos.album_id AND photo.visible=1 In that part, kill4silence_photos_albums is considered to be the left table, and kill4silence_photos_photos is the right. The condition after the ON is the join condition. When you do a LEFT join, then the database takes all matching rows from the left table, and attempts to find matching rows in the right table based on the join condition. If it finds no matching rows, then it uses an implicit all-null row to match against. Essentially, that means you will always get the full result of rows from the left table (all the albums). For each album it will find any photos belonging to that album. if there are none, it just uses a NULL row to fill in the blanks. Then the GROUP BY clauses tells it to group the results by each unique album id, and the COUNT() function will give a count of all the photo id that are non-null. For an album that has photos, this will be the number of photos matched. For an album that has no photos, it will be 0.
  19. Use something like Fiddler2 to record all the http transactions as you go across the site, look at the cookie headers your scripts are sending (Set-Cookie headers in the response area) to see what is happening. Open fiddler2 Open your browser and go to your site Login, and hit a page or two Logout and then hit a page or two. If you want, yo-u can save all the sessions and send them to me and I will see if I spot anything unusual. I have PM'ed you my email address.
  20. If your session cookie is sticking around (with the same id) then a few possibilities are: 1) You've configured PHP to set an expires date/time on the cookie, rather than using 0 to make it a session cookie (generally not wise) 2) You're not closing the browser completely. Session cookies only go away when the browser is fully closed. You have to close all windows, not just the single window or tab your site is in. 3) Your somehow re-starting the session with the same id Regardless, having the session ID stick around is not anything to really be concerned about. Provided you have cleared out the data in the session (ie, your session_destroy/$_SESSION=array() combo would do that) then that ID is just going to be linking to an empty session file. Session hijacking has less to do with the session id sticking around after logout, and more to do with people intercepting your session ID while it is in use, such as by using a packet sniffer to watch requests on the network and stealing the ID that way.
  21. Nowhere. Your browser is the one that handles the actual storage of the cookie data. Where it stores it depends on the browser in use. I believe firefox stores them in a SQLite database somewhere in the profile folder. If you want to remove the cookies, just use the browser's tools for that. Either to clear all cookies or a cookie manager that will let you single out specific ones for removal. In firefox you go to Options->Privacy and click the 'remove individual cookies' link.
  22. The only way you'll get your tree structure (reverse breadcrumb) with your current db structure (without a multiple-select loop) is to select everything from your albums table and build the tree in PHP. You can have a second query which pulls the count of photos in each album and merge that into the tree while you build it. //Get photo count $sql = ' SELECT album.id as album_id, COUNT(photo.id) as cnt FROM kill4silence_photos_albums album LEFT JOIN kill4silence_photos_photos photos ON album.id=photos.album_id AND photo.visible=1 GROUP BY album.id '; $res = mysql_query($sql); $photoCounts=array(); while ($row=mysql_fetch_assoc($res)){ $photoCounts[$row['album_id']] = $row['cnt']; } $sql = ' SELECT id, parent_id, name, description FROM kill4silence_photos_albums ORDER BY parent_id '; $res = mysql_query($sql); $albumTree = array(); $albumMap = array(); while ($row=mysql_fetch_assoc($res)){ $id = $row['id']; $parent = $row['parent_id']; $row['children']=array(); if (isset($photoCounts[$id])){ $row['photoCount'] = $photoCounts[$id]; } if ($parent != 0 && isset($albumMap[$parent])){ $albumMap[$parent]['children'][] =& $row; } else if ($parent == 0){ $albumTree[] =& $row; } $albumMap[$id] =& $row; unset($row); } If your going to run mysql_close at all, only run it at the end of the script. Closing the connection after every query is wasteful and only going to make the script even less efficient.
  23. If you want to get the sub-albums then you just query for all the albums who's parent_id is the current album. You can do that and get your # of photos per album in a single query.
  24. What you pasted is not JSON. It is a string of serialized data, and you can reverse it using unserialize. After you unserialize it you can access the key 'calendarJson' which contains json and you can decode that using json_decode.
  25. Not if your table is indexed properly. The database will just scan the index to find the specific rows it needs, rather than having to go through every row. There are other ways to improve performance too such as partitioning. Until you reach numbers in the millions for your number of rows, you shouldn't see and big problems with just some indexes.
×
×
  • 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.