Jump to content

Wolphie

Members
  • Posts

    682
  • Joined

  • Last visited

    Never

Everything posted by Wolphie

  1. He's not working with a database. He's using an XML file.
  2. This isn't related to the question, however... when storing users IP addresses you MUST state in your privacy policy that you store their IP addresses, and explain why/what they're used for. Regarding the question... Try: $insert = sprintf("INSERT INTO 404s ( id, ipaddy, whenreq, referpage, pagereq ) VALUES ( NULL, '%s', '%s', '%s', '%s' )", $ipaddy, $serverdate, $referpage, $requestedaddress);
  3. Using MySQL functions you can extract each row from a table and it will be stored in an array. You can then use a while loop to loop through every row in the database and put it into an array, then use that array however you choose. Example: <?php $result = mysql_query("SELECT name, email FROM mailinglist"); while ($row = mysql_query($result)) { echo $row['name'] . '<br />'; echo $row['email'] . '<br />'; } ?> That will list all of the names and e-mail addresses stored in the database.
  4. Yes, this worked for me in all A-grade browsers. (although not sure about IE6)
  5. No, well at least it shouldn't do. It might seem like it, but it shouldn't. The only way to find out would be to test it. I don't use an automatic redirect, I actually use a link which a user clicks. Once clicked, the download begins and the current page remains unchanged. I don't see any reason why using an automatic process would be different.
  6. I'm not sure if this would be the best way to do it, however you could add a time column in the users table. When a user logs on, or visits a page (all pages) update the table with the current time. If that time is older than 5 minutes (or what ever you choose) then set the value to 0. You could improve the process a little bit more by adding a script inside crontab to run every 5 minutes to check the times. Like above, if the time is 5 minutes in the past, then set the value to 0.
  7. <?php echo date('j M, Y', 1254598665); ?> Result: 3 Oct, 2009
  8. You could always use a Javascript re-direct in that case since you're using Javascript for AJAX anyway. Add a callback... once the AJAX request has been processed, proceed to re-direct the user to the page which will generate the file.
  9. It should work just fine. When an AJAX process has completed, the content becomes a regular web page and it could be treated as such. I.e. the user opts to download the excel file, you validate the input etc. and if all is okay, you can do a PHP header re-direct to another PHP page that actually generates the file. The download begins and the user still remains on the same web page.
  10. Personally I'd be more inclined to do something like: $car = $_GET['car']; $cars = array('Volvo', 'Ford', 'Nissan', 'Toyota'); $select = '<select name="cars">'; foreach ($cars as $key => $val) { $select .= '<option value="'. $val .'"'; if (isset($car) && $car == $val) { $select .= ' selected="selected"'; } $select .= '>'. $val .'</option>'; } $select .= '</select>'; echo $select; ?>
  11. Why does it need to be a popup? You could easily just redirect them to a PHP page that generates the file. I've used this method before, and it doesn't actually take you away from the current web page. I.e. it won't send you to a blank page when the file is being downloaded. As soon as the page is redirected or a link is clicked, the download will begin and the user will remain on their current page. This eliminates the need for javascript if you use a PHP header re-direct.
  12. <pre> <?php $numbers = array(rand(1, 45),rand(1, 45),rand(1, 45),rand(1, 45),rand(1, 45)); $questions = array(rand(1, 45),rand(1, 45),rand(1, 45),rand(1, 45),rand(1, 45)); print_r($numbers); print_r($questions); $i = 0; while (true) { if ($i == count($numbers)) { break; } else { if (!in_array($numbers[$i], $questions)){ break; } else { echo 'Found!'; } } $i++; } ?> </pre> Result: Array ( [0] => 5 [1] => 6 [2] => 36 [3] => 41 [4] => 12 ) Array ( [0] => 7 [1] => 5 [2] => 27 [3] => 38 [4] => 37 ) Found! Note: The number 5 occurred in both arrays, therefore "Found!" was displayed on page.
  13. Do you mean a counter on a website that counts down while you're on the page? If so, this can only be achieved in JavaScript/Flash or Java.
  14. .zip is a binary file, you need to open the file in binary mode. This just involves adding a 'b' to the second parameter of fopen. I.e. fopen('path/to/somefile.zip', 'rb') (read only, binary).
  15. Do you have an example input? (I.e. the string you're trying to split)
  16. You should check out the explode function: http://php.net/manual/en/function.explode.php <?php $name = "John Smith"; $names = explode(" ", $name); echo $names[1] ." ". $names[0]; // Smith John ?>
  17. You should learn about http://php.net/manual/en/language.variables.scope.php
  18. I don't think the file upload form element allows you to set a default value. If it did, this would be a major security issue since it would allow attackers to automatically select a file in the form element and then hide the element from the user, making them unaware that a file is being uploaded when they send the form.
  19. Yes this is possible using regular expressions. http://php.net/manual/en/function.preg-match.php <?php // File name, could be a url $str = '<img src="http://www.example.com/upload/2010/07/t_shutterstock_2674130.jpg">'; $pattern = '/upload(.*?).jpg/s'; $content = preg_match($pattern, $str, $matches); print_r($matches); ?> results in: Array ( [0] => upload/2010/07/t_shutterstock_2674130.jpg [1] => /2010/07/t_shutterstock_2674130 )
  20. Do you mean highlight each occurrence of the search word on the page?
  21. http://php.net/manual/en/function.include.php include 'counter.php';
  22. This should work (the file_exists() function will not work on a URL) <?php function create_link($matches) { // link_id should be an auto-increment field $insert = mysql_query(sprintf("INSERT INTO links ( link_url ) VALUES ( '%s' )", $matches[1])); return '<a href="' . mysql_insert_id() .'">'. $matches[2] .'</a>'; } // File name, could be a url $file = 'file.html'; if (file_exists($file)) { $content = file_get_contents($file); // Regex replace string $pattern = '/<a href="([^"]+)">([^<]+)<\/a>/s'; $content = preg_replace_callback($pattern, 'create_link', $content); echo $content; } ?>
  23. The PHP documentation is amazing, by the way. http://php.net/manual/en/function.file-get-contents.php http://php.net/manual/en/function.preg-replace.php
  24. In your case you should be using echo $_FILES['file']['error'];
×
×
  • 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.