Jump to content

Bauer418

Members
  • Posts

    206
  • Joined

  • Last visited

    Never

Everything posted by Bauer418

  1. I'm aware of garbage handling and session_set_save_handler. That wasn't my question. I was wondering if there was a better way to create sessions that end with a browser close and are cleaned up shortly after, rather than just setting an arbitrarily long expiration time. In any case, I'm making a custom session class that doesn't use PHP's built-in system since I would need to change so many thing with it anyway.
  2. Actually...you just took out a bracket that he needed, his code won't parse now. @NaveAdair: I'm not sure exactly what your code is supposed to do. To upload files, you need to be using the $_FILES array, not the $_POST array. Why are you passing $_POST['pic1'] to upload()?
  3. The below code is just an example of how to do it. I trust you can adapt it to your needs: <?php $spamList = array('word1', 'word2', 'word3'); function checkSpam( $input ) { global $spamList; foreach ( $spamList as $spamWord ) { if ( stripos( $check, $spamWord ) !== false ) return strtolower( $spamWord ); } return false; } if ( $badWord = checkSpam( 'This should detect word1 spam') ) { print 'The following word is not allowed: ' . $badWord; } ?>
  4. I want the session to last until they close their browser, but I also need someway to clean and maintain the database, so there aren't week-old session entries in there. I have settled on the fact that the only way to do it is with an arbitrarily long session timeout as I mentioned earlier. Probably 24 hours, so there's no need for this topic anymore. Thanks though.
  5. @premiso: Please read the requirements before telling people their solutions are wrong. He wanted to get rid of the newline character, not just add an HTML line break. @NamemeNick: The \r is a carriage return, the combination of \r\n usually results from a newline entered on a Windows OS. Linux uses simply \n to denote a newline. You have to make these extra checks to be sure, so I would change your code to: $input=str_replace(array("\r\n", "\n"),"",nl2br(htmlentities($_POST["field"]))); To be sure you capture both types of newlines.
  6. str_replace("\n", "", nl2br($input)); Converts new lines to <br /> and then gets rid of the newline character.
  7. It suppresses error messages for the code that it prepends.
  8. Seems like more work if substr_count works perfectly...just tested it.
  9. Echo your queries first. Second, may I suggest that you find a different way to update your users table. Your method is, well, not the most efficient. That entire function full of MySQL UPDATE queries could be consolidated.
  10. No problem. If you could though, please mark the post as solved so people know your issue is resolved! Thanks.
  11. FYI: I believe you're looking to close the "<h20>" tag that is opened just before "The Latest" near the top of the page.
  12. http://www.google.com/search?source=ig&hl=en&rlz=1G1GGLQ_ENUS314&=&q=php+create+zip+archive&btnG=Google+Search&aq=f&oq= I hate PHPClasses personally, but the first result looks promising (I didn't look at the page at all, just the title).
  13. PHP is not going to change the font of your page. Unless your PHP generates your HTML programmatically, which it likely does not.
  14. Good call. I figured because DATE is a data type it would be reserved, but evidently they allow it (as seen in the list of acceptable unquoted strings below the reserved keywords). Likely a column/table identifier error then. As always, mysqli_error will have your answer.
  15. Or...anyone's help. Sounds to me like you just want someone else to dig through your HTML. Bottom line: find the tag and close it. It's not a difficult task.
  16. Ah. I didn't notice you had to references to the same code, and I only changed one. Basically, you should change: $display = str_replace($key, $value, $file); to: $file = str_replace($key, $value, $file); The reason is because you want to process a template variable, save the replaced result in the variable "file", then use that replaced result while you search for the next template key, and so on.
  17. Place ticks around your column names, so you change: INSERT INTO Equipmentposting (date, type, title, price, email, content, img1, img2, img3) VALUES ('2009-04-23', 'General Laboratory', 'asdf', 'asdf', 'asdf', 'asdf', '1240517000BETA-UNDER-CONSTRUCTION.jpg', '1240517000discussion.jpg', '1240517000reviews.jpg') to the following: INSERT INTO Equipmentposting (`date`, `type`, `title`, `price`, `email`, `content`, `img1`, `img2`, `img3`) VALUES ('2009-04-23', 'General Laboratory', 'asdf', 'asdf', 'asdf', 'asdf', '1240517000BETA-UNDER-CONSTRUCTION.jpg', '1240517000discussion.jpg', '1240517000reviews.jpg') The reason you need this is because date (and possibly type, though I don't remember exactly) are reserved MySQL keywords. The ticks around the column names indicate that it is a reference to the column, and not the MySQL keyword. @ram4nd: no. He using the mysqli extension, not the mysql extension.
  18. Place a period "." in front of the first slash, making the path: "./images/product029.jpg" or simply remove the first slash and period. The reason is because the / refers to the root of the directory structure. The period is a reference to "this folder" similar to the way that the double periods refer to "parent folder." In other words, if you are currently in path: /var/www/display.php and you say: require("/content.php"); you will try to load the file /content.php, though surely what you want is to load /var/www/content.php. Sort of difficult to explain, and I'm trying to get back to you within your time frame.
  19. The problem is in your str_replace function. You are always replacing the contents of "file" and storing it in "display." Each time you make a replacement, you store the result in display, and move on to the next one. Sounds good, right? Except, on the next replacement, you open the original file contents again and store the result in display again. Consider this code: <?php if($_POST['submit']){ $book = array( 'FIRST_NAME' => $_POST['authfirst'], 'LAST_NAME' => $_POST['authlast'], 'MI' => $_POST['authmi'], 'TITLE' => $_POST['booktitle'], 'PUBLISHER' => $_POST['publisher'], 'PULICATION_LOCATION' => $_POST['publocation'], 'VOLUME' => $_POST['volume'], 'DATE' => $_POST['date'] ); $file = file_get_contents("templates/displays/MLA_book.tpl"); foreach($book as $key => $value){ $display = str_replace($key, $value, $file); } echo $display; } else { $vars = array( 'ACTION' => $_SERVER['PHP_SELF'] ); $file = file_get_contents("templates/forms/MLA_book.tpl"); foreach($vars as $key => $value){ $file = str_replace($key, $value, $file); } echo $file; } ?>
  20. I'm working on a PHP session management system that isn't based on the standard PHP session system. I'm trying to achieve an effect similar to Facebook where a user is logged in as long as the browser is open. When the browser is closed, the session is no longer active, unless they have checked "Remember Me." I'm aware of how to set a cookie that will end when the browser is closed, but the issue arises when the session data sits in the database because I have told it not to expire. I consider myself fairly advanced when it comes to PHP, so I'm not looking for any sort of code, rather just a possible way to achieve the desired result. Here's a sample scenario: [*]User first visits the site, a session is created for that user [*]The user logs in, and the session now remembers their user id [*]The user leaves their computer for a couple of hours, returns, and their session is still active [*]The user closes their browser window, re-opens it, and returns to the site [*]Their previous session is no longer valid, they must login again [*]The session data is removed from the database Should I just set an arbitrarily long session timeout? Any other suggestions?
  21. Most *nix based systems don't store the created date, which is why PHP doesn't have a simple way of accessing it.
  22. Probably: $data = file('file.txt'); print $data[$n - 1]; file() creates an array with a new element for each line. I'd be curious to see if there's a better way. If you know the length of each line, you could combine fopen, fseek, and fread.
  23. The GET method works fine for this approach. The id in the URL is not sensitive data at all. You don't even need an onclick. Simply <a href="/go.php?user_id=8037&token=ae1c65bbc4e2eb5bcd269273bc80ff4c">Text</a> The onclick method would work better for search engines, but then you won't get links counted from anyone that has javascript disabled.
  24. Yes. You don't need to use exceptions where you already have if statements. This whole block: try { if (!@include_once $_SERVER['DOCUMENT_ROOT'].'/classes/template.class.php') { throw new Exception("EXCEPTION : REQUIRED CLASS - TEMPLATE - NOT FOUND!!"); } } catch (Exception $e) { echo $e->getMessage(); die(); } Will product the same results as this: if (!@include_once $_SERVER['DOCUMENT_ROOT'].'/classes/template.class.php') { print("EXCEPTION : REQUIRED CLASS - TEMPLATE - NOT FOUND!!"); exit; }
×
×
  • 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.