Jump to content

requinix

Administrators
  • Posts

    15,265
  • Joined

  • Last visited

  • Days Won

    431

Everything posted by requinix

  1. Since you're just starting out, this is an excellent chance for someone like me to point out all the things you should be doing right. That way you don't have to relearn (and rewrite) things later when you discover you've been doing something wrong. // root is the admin user for mysql. do not use it to connect to your database in your scripts // create a restrictive user just for the things you need it to do. for example, "simpleuser" $con = mysql_connect("localhost", "simpleuser", "simplepassword"); // to create this user, use whatever tool you have available (like phpMyAdmin or CPanel) // you can create one using a query too. temporarily connect as root and run // GRANT SELECT,INSERT,UPDATE,DELETE ON users.* TO simpleuser@localhost IDENTIFIED BY 'simplepassword' // - SELECT, INSERT, UPDATE, and DELETE are the operations you want to allow simpleuser to do // (as a simple user it shouldn't be able to alter tables or delete databases) // - "users.*" means all the tables in the `users` database // and be sure to change the username and password to something relevant if (!$con) { // do not reveal mysql errors. for now, just show a simple message die("Could not connect to the database"); // later you can learn to log these errors someplace and show a better message // (without having to kill the script to do so) } mysql_select_db("users", $con); // if you ever use anything from $_GET or $_POST in a query, you need to make sure it's safe to use first // for string values use mysql_real_escape_string() right when you put the string into the query $query = "SELECT * FROM user WHERE username = '" . mysql_real_escape_string($_POST["username"]) . "'"; // there are other tools like PDO and mysqli which are "better" to use. when you understand how SQL works // then you should use those, but I do recommend starting off with just the mysql_* functions so you // learn about concepts like SQL injection // now execute the query $resultset = mysql_query($query, $con); // and try to get a row $user = mysql_fetch_array($resultset); // if you were able to get a row then that must mean there's some user with username=$_POST[username] if ($user) { ?> Site Content Back To Login. } else { ?> Wrong Username Back To Login. }
  2. And you're absolutely sure that you're going to http://www.example.com/example-1.html? Because I don't see anything else that could be the problem. How about using a RedirectMatch then?
  3. You didn't happen to look at Chrome's error console, did you?
  4. Can I assume the .htaccess is being interpreted? In what folder is the file and what URL are you trying?
  5. Try RewriteRule ^/?example-(\d+)\.html$ /$1.html [L,R] And remove the second RewriteEngine directive - one is enough.
  6. 1. Windows's CLI doesn't support & for running in the background. That's a Linux thing. Use `start` like in the example I posted. 2. The -- is for php.exe so it doesn't think that whatever comes after is an argument for itself. 3. Your batch file has to pass its arguments to the script. 4. Variables don't work inside singly-quoted strings. 5. bkupdate.php will not get the $argv1 variable. You can only use the $argv array. Like in the example I posted. shell_exec('start test.bat ' . escapeshellarg($argv1)); @echo off "C:\Program Files (x86)\PHP\php.exe" -f C:\inetpub\test\bkupdate.php -- %1
  7. On Windows you'd use start, like shell_exec('start test.bat'); But are you using batch files? Not PHP? In PHP you'd look at $argv as in if ($argc >= 2) { // script name always comes first, so $argc=2 means 1 argument echo "argv[1] = {$argv[1]}\n"; }
  8. Ads in your RSS? Please no.
  9. $_POST["chk1"] and $_POST["chk2"] are the two checkboxes you made. Specify the background color accordingly.
  10. Percentages only work in CSS rules. document.getElementById(id).style.width = va;
  11. is_numeric() will accept real and negative numbers. Try ctype_digit instead. Your regex needed start-of-string and end-of-string anchors, otherwise it only checked if the input contained a 10-digit number. /^[0-9]{10}$/
  12. So in other words you downloaded a lot of data from a website, apparently about its users, and you want to import that into your own database? Care to elaborate on why?
  13. There are a few ways that depend on server configuration, so unless you have full control of your web server you should use the most reliable and most portable technique: Make a command-line script to do what you want. If it needs arguments then they should be passed as command-line arguments (which you can get with $argc and $argv). Then in the original script you call it like `php -f /path/to/script.php -- other arguments you need to pass to it &`; The trailing & is what makes the script run in the background. Other solutions include: - Ending the response so everybody else thinks the script is done. I've had mixed luck getting that to work consistently. - Using process-level control (like popen) to run PHP, like the command does above. Sometimes these functions are disabled, and most commonly on shared hosting servers. - Forking a process, but this almost never works due to extensions and functions being disabled, or the server (eg, Apache) not supporting the kind of operations forking entails.
  14. So hungry... but it's not even 11 yet D: This topic has been moved to mod_rewrite. http://www.phpfreaks.com/forums/index.php?topic=360284.0
  15. Then you need mod_rewrite, not Redirect or RedirectMatch. RewriteEngine on RewriteRule ^example-(\d+)\.html$ /$1.html [L,R] [edit] I'm totally wrong: you can do it with RedirectMatch too. Check the manual page for an example how.
  16. Define "working".
  17. Have you considered a simple UPDATE table SET field = field - 1 WHERE field > value you just deleted
  18. This topic has been REPLACEd INTO MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=360250.0
  19. You didn't escape the quotes in the link HTML.
  20. You can't put port numbers or paths into DNS. Only hostnames and IP addresses. You have three options: a) Have people change the configured location of the Exchange server in their clients b) Make www.sitename.com resolve to the XXX address, or move Exchange to that machine c) Have the www.sitename.com server proxy requests for www.sitename.com:81/exchange/ to the new location. This is a bad choice
  21. Should the $settings[0]= line be just $settings=?
  22. Warning: explode() expects at least 2 parameters, 0 given Surely I'm not the only one who thought that...
  23. In your database or wherever, categorize images according to the criteria you want. Then in the code your query can pull (randomly) from images that are in some specific category. Or you can go a more complex but more flexible route and use date and time ranges for each image then pull (randomly) from whatever is in the range. I also recommend designing the randomization process so that whatever image it picks stays for a while - like an hour or so. Otherwise every page load could pull up a different image and that could be quite distracting for your users. If you're worried about the additional complexity then let me tell you that it would be a very trivial modification. Stop for a lunch break? (At 3am?) A holiday? But the Internet doesn't have lunch breaks or holidays...
  24. if (item is not "do not replace") { update database with new item }
  25. You're saying this "do not replace" code is already written and ready to be used? Then add a Whatever you want it to say into the SELECT - probably as the first option.
×
×
  • 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.