Jump to content

kicken

Gurus
  • Posts

    4,704
  • Joined

  • Last visited

  • Days Won

    179

Everything posted by kicken

  1. Just to clarify, do you want it to be the value contained in the $value['title'] variable, or do you want it to be literally '$value['title']'? If the former, var_dump $value to make sure it contains that key and that it has a value to start with. If the later then you need to either escape the $ or use single quotes around the string. $array1['%%title%%'] = "\$value['title']";
  2. If you're only displaying one, then you don't need the implode statement. echo '<img src="'.(explode(',', $row["PictureRefs"])[0]).'"/>'; If you get a syntax error due to the [0] then your PHP version is not new enough for that syntax. You will need to assign the results of the explode to a variable then use that variable instead. $var = explode(',', $row["PictureRefs"]); echo '<img src="'.$var[0].'"/>'; Note that having delimiter-separated values stored in the database like that is typically a sign of bad design and you should re-think your database design.
  3. Javascript is not Java, they are two entirely separate and distinct languages. Neither Javascript nor PHP will allow you to profile a systems hardware. Java might let you do it, I am not certain of it's capabilities in that area. You would be best served posting on a Java forum for help.
  4. Not by a third-party in the middle, which is what your whole post is about.
  5. INSERT queries do not have a WHERE clause. Remove that. This should be triggering your query fail error message, so if you are not seeing that then you need to do as suggested above and make sure that branch of code is running.
  6. Congrats
  7. I haven't used phpMyAdmin in a long time, so I haven't seen what you're talking about however I would guess they are just using a JS based dialog, such as JQuery UI's Dialog. The basic process probably goes something like: - phpMyAdmin sends request to server via Ajax - Server responds with authentication error - phpMyAdmin opens login dialog - phpMyAdmin sends login details - When successful authentication occurs, phpMyAdmin repeats original request.
  8. When is a Left table 'Left' and a right table 'Right' Read that for some information on what they different join types are and when they are appropriate.
  9. It reduces the work that the database server has to do. Normally when you run a query the server has to go through a number of steps, namely - Parse the query text into it's components - Examine the the query and optimize it if possible - Develop an execution plan for how it will actually process the query - Execute the execution plan When you prepare the query, it performs the first three steps, but not the last. When you call the execute method it performs the last step with the appropriate values for the parameters. So if you need to run the same query a number of times in a loop with just different parameters, by preparing the query prior to the loop rather than within the loop you can save the database server some work by not requiring it to run the first three steps on each loop iteration. You are correct, you can only bind values in a query, not identifiers (like table/column names) or syntax items (like a JOIN clause). One other common misconception is that you can do something like ... IN (:param) and have :param bound to an array or comma-separated list. This does not work, you have to use a separate parameter for each possible value in the in clause.
  10. Occasionally new developers have a misconception that by simply using the prepare() method they are somehow magically protected from SQL injection. This conception is someone re-inforced when people say "Use prepared queries to prevent injection". The act of preparing a query does nothing for protecting you from injection. It is using bound parameters that will offer you the protection. As such, it'd be more accurate to say "Use parameterized queries to prevent injection". In order to use parameters you must first prepare the query though, which is why some people will use the terms interchangeably when they really shouldn't.
  11. Assuming you are talking about Godaddy's shared hosting, as far as I know, godaddy does not allow you to run continuous processes in the background which is what would be required for your server.php file. It may run for a few minutes, but eventually Godaddy will kill the process. Aside from that, they probably have their firewalls setup to disallow incomming connections on other ports so your web clients would not be able to connect to the server anyway as the connection would be blocked. For what you want to do you'll need a dedicated or VPS server most likely. Something where you can control how it is setup and what is allowed to run.
  12. There's nothing wrong with spending some time with just a text editor and a console and learning gcc/g++, make files, gdb, etc. You can learn quite a bit about the inner workings of the software development process and what happens when you hit the 'Build' button in the IDE. The IDE's generally provide a lot of nice features to help speed up development and reduce the amount of stuff you need to remember or lookup. For instance in most IDE's setting a break point on a particular line in an IDE is usually a simple matter of clicking in the margin to toggle the breakpoint. With GDB on the command line you'd have to type a command such as br thefile.c:1234 meaning you need to know the name of the file and the exact line number. Not complicated information to find, but also something you shouldn't need to do. There's numerous other things an IDE will help with which while possible w/ gdb or other manual tools are simply more cumbersome.
  13. As far as I am concerned they serve the same purpose. Having two different buttons would just be unnecessary clutter.
  14. As far as I know, no there is nothing that you can append to the URL that will toggle the compatibility mode, only the meta tag / header. That said, you could designate your own URL switch that will cause your application to output the appropriate meta tag only if present. That might be what was being mentioned.
  15. GDB is the main command line debugger. Some IDE's simply interface with this rather than having their own debugging routines. You can google for a tutorial to cover the basics of GDB and get started with setting break points and stepping through the code. IDE's make the debugging process much simpler and more user friendly but are certainly not required. Another tool you'll likely want to look into which can help with memory problems such as corrupted data and segmentation faults is Valgrind. It will report back any attempts you make to access (read or write) memory locations that you should not be.
  16. They are using this. As mentioned though, this will allow things that some people would not consider to be a valid number, such as 0xBEEF. Neither of these will help. They test the data type of the variable, not it's contents. All form data is a string, so is_string would be true and is_int would be false regardless of the actual values they contain. @joker53142 ctype_digit is one way to check for a numeric value if you do not need to allow decimal points or negative numbers. Otherwise you'll probably want to use a regex with preg_match or check individual characters such as with a loop and list of valid characters as shown above. <?php $regex = '/^-?[0-9]+(\.[0-9]+)?$/'; if (preg_match($regex, $number1) && preg_match($regex, $number2)){ //valid numbers } The regular expression above checks that a string consists of only digits and optional a - at the start for negatives and a optional . followed by more digits for fractions.
  17. Use the password_hash function. Specify PASSWORD_BCRYPT rather than the default and do NOT specify a salt, let PHP generate it for you. You should specify a cost however. password_hash($password, PASSWORD_BCRYPT, array('cost' => 14)); You'll want to play with the cost value until the function takes about a second to complete. You can measure the time using microtime, such as: <?php $s = microtime(true); password_hash('abcdefg', PASSWORD_BCRYPT, array('cost'=>14)); $e = microtime(true); var_dump($e-$s); When storing the hash to the database there is no reason to convert it into some kind of binary representation, whatever you mean by that. Just store the string into a VARCHAR column. As for the why, MD5 has collision weaknesses, and both it and SHA are fast algorithms which is NOT a good thing for password hashing. For password hashing you want an algorithm that is slow and/or memory intensive so that someone who is trying to brute-force the hashes is forced to spend a lot of time on it and/or expend significant resources. bcrypt is designed for password hashing and is slow and expensive. It does however have it's own limitations that you should be aware of.
  18. I just open up my collection and put it on random. Has everything from mood music to metal.
  19. If you want to go cutting edge, you could look into Websockets, optionally using something like Socket.IO for compatibility. Otherwise you'd do standard AJAX requests to poll the data for new information as well as push new information to the server. When polling for new data you'd need to send some kind of indicator to let the server know what data you've already received, such as a timestamp of the last polling time. As far as the polling goes you have two basic options: Long poll - The server will block on the request until it has new data to send. This minimizes the number of requests and bandwidth needed but ties up the servers processing threads. Short poll - The server will return quickly either with the new data or with nothing. A new polling request must be sent periodically. This increases the requests made and bandwidth used but keeps the server's processing threads open With a little extra work you could go in between long and short and have a timeout. The server could wait for say 30 seconds for new data before returning an empty response. Your server resources would not be tied up long and you can save some bandwidth with fewer requests.
  20. You could use basename to extract just the last bit. Apparently that only works on windows. ltrim + strrchr could be used instead. $c = get_class($object); ltrim(strrchr($c, '\\'), '\\')
  21. One additional thing to mention, you need to ensure that when you create the document you need to ensure that your editor saves the document as UTF-8 as well. If you create and save your document in something like Windows-1252 but tell the browser that it's UTF-8 you'll still have issues because the literal curly-quote will not be encoded properly. This is a somewhat common issue to people who are new to character encoding. They will configure their page with the meta tag and/or header but neglect to ensure they are actually creating a UTF-8 page in the first place with their editor.
  22. The + operator applies to 'Addition: 4' and 2. 'Addition: 4' is a string, not a number so PHP will attempt to convert it. Since it is not possible to convert it however you end up with zero so the end result is you have 0 + 2.
  23. If you evaluate it one operator at a time and sub the results into the original equation you can see what happens. echo 'Addtion: ' . $x + $y . '<br>'; Evaluate the first . operator, result is: 'Addition: 4', so then you have: echo 'Addtion: 4' + $y . '<br>'; Evaluate the + operator. PHP try and convert the first operand to a number but since the string is not a valid number you get zero. Now you have: echo 2 . '<br>'; Which gives you a final output of '2<br>';
  24. When your account was changed, it most likely also changed the version of PHP you are using. In this case likely to something older which does not support anonymous functions. If you have the ability to select your PHP version, make sure you are using PHP 5.3 or newer for that feature. If you can't control this yourself you'll have to ask your host to update. By adding the battery as a parameter to the constructor it allows the code creating the device to control what kind of battery is used for the device. Say in the future you have several different types of battery classes, eg class NineVolt extends Battery, class TwelveVolt extends Battery, , class TwentyFourVolt extend Battery. All three of those classes are of type Battery and any of them could be passed into the constructor. When you simply create the battery inside the object by doing $this->battery = new Battery you are creating a hard dependency between those two classes and do not allow for the ability to use different battery types in different instances of your device class. If you want to learn a bit more, read up on Dependency Injection.
  25. MAC addresses are not maintained across the network path like IP addresses are. A computer only ever sees the MAC of whatever the previous computer was in the path. Typically this is whatever router the computer is connected to. I'm guessing in this case they are dealing with a router in which case the MACs of each computer connecting to the router will be available and will be unique.
×
×
  • 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.