Jump to content

Psycho

Moderators
  • Posts

    12,145
  • Joined

  • Last visited

  • Days Won

    127

Everything posted by Psycho

  1. Hundreds of variables? I doubt you really need all of those and it could be streamlines with better code. Otherwise, you should use array variables. E.g. $vars['a'], $vars['b'], etc. Then, at the very least, you could run a loop to zero all of them out or have a template array to set the initial state. But, as requinix stated, it would be nice to see the code as we can probably find a better solution.
  2. FYI: If you are doing an ON DUPLICATE KEY UPDATE, there is a way to reference the INSERT values in the UPDATE portion of the query instead of having to reuse the variables. I find this a better approach. If you have a typo in the variable name you may not catch it. But, if you mistype a field reference it would produce an error regardless if whether the INSERT or UPDATE is run. Also, I would highly advise creating your queries as string variables so you can echo them to the page for debugging purposes. Plus, using tabs and spacing to format the query in a readable format helps save a lot of time. E.g. $query = "INSERT IGNORE INTO mxit (ip, time, user_agent, contact, userid, id, login, nick, location, profile) VALUES ('$ip', '$post_time', '$mxitua', '$mxitcont', '$mxituid', '$mxitid', '$mxitlogin', '$mxitnick', '$mxitloc', '$mxitprof') ON DUPLICATE KEY UPDATE ip = VALUES(ip), user_agent = VALUES(user_agent), contact = VALUES(contact), login = VALUES(login), nick = VALUES(nick), location = VALUES(location), profile = VALUES(profile)"; $result = mysqli_query($con, $query) or die(mysqli_error($con));
  3. Also, some email clients will disable links based on various rules - typically to prevent the user from clicking malicious links. Have you tried reading the email is different email clients?
  4. Yeah, but that would have probably required a JOIN!
  5. $body .= 'Selected Projects: ' . $selectedProjects; $fields{"contact-comments"} = "Message"; $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } Look closely at the first and last lines above.
  6. Psycho

    checkbox

    As to your code, you do not change the value of the checkbox. And, in this case the value really isn't important. The checkbox should use the same value and you should check/uncheck it based upon the saved data. Also, you should save the value as a numeric equivalent of a Boolean, i.e. 0 (false) or 1 (true). visible: <input type="checkbox" name="inp_vis" value="visible" <?php echo if ($row['vis']) "checked='checked'"; ?>>
  7. I think I understand the select fields to be just that - HTML select fields. However, I too am perplexed by what is meant by an "unlimited text field with an 'add more' option". Never heard of such a thing. And, if the field is "unlimited" what is the purpose of an "add more" option? In any event, it sounds like you want a JavaScript solution, not PHP. If so, this is in the wrong forum.
  8. You wrote that incorrectly. It should be "I distract easily and . . . squirrell!"
  9. I've been 'scolded' in the past for not looking up from my screen when people come to my cube to talk with me. I can listen to what they are saying and carry on a conversation while working. But, apparently they "feel" I'm not giving the attention they deserve because my eyes are not trained on them.
  10. If you are going to build logic to 'calculate' the process date, then you don't need to save it in the database and instead use that calculation when needed. But, I could see where some things may be easier to accomplish if you have that value saved. So, I will not tell you to do it one way or the other, but I will show you how to get the date in question. The logic could look something like this: SELECT -- If the Day of received date is <= 9 IF(DAY(received_date) <= 9, -- Then Use 9th of current month DATE_FORMAT(received_date, '%Y-%m-09'), -- Else use 9th of next month DATE_FORMAT(DATE_ADD(received_date, INTERVAL 1 MONTH), '%Y-%m-09') ) as processed_date Basically we test the "day" of the received date. If it is less than 9 (1-9) then we determine the processed date tot he 9th of the given month. Otherwise we determine it as the 9th of the next month. An update query to set a value in the new column might look like this UPDATE `table` SET processed_date = -- If the Day of received date is <= 9 IF(DAY(received_date) <= 9, -- Then Use 9th of current month DATE_FORMAT(received_date, '%Y-%m-09'), -- Else use 9th of next month DATE_FORMAT(DATE_ADD(received_date, INTERVAL 1 MONTH), '%Y-%m-09') )
  11. I don't think this is a networking issue. You have to already be connected to the network in question in order to implement what you want. There is no way for a web page to connect a computer to a different network. You need to have your router redirect users to a page where you will run the logic to determine if the user is "authorized" or not. This is what you would see in a public Wifi. Sometimes you just need to accept some Terms of user and sometimes you need some sort of authentication (e.g. room number and name). I assume the page used for that simply passes back a confirmation to the router in some manner. So, you can probably do this with just PHP, but you would need to know how to configure the router to use your custom page and what data your page would receive and need to pass back to the router. Not to mention, the router would have to support that functionality in the first place. Apparently this functionality is referred to as "Captive Portal" Here are a few links that may help: http://www.bleepingcomputer.com/forums/t/506654/help-wifi-custom-login-page/ http://www.wi-fiplanet.com/tutorials/print.php/3730746 http://www.pcworld.com/article/2031443/how-to-set-up-public-wi-fi-at-your-business.html
  12. I'm pretty well versed in networking technology, but I'm no expert. I think you are misunderstanding what is happening. A web page can't "connect" you or redirect you to a wifi network. You have to already be connected to the wifi network to access the login page. This is what is likely happening: You connect to the Wifi network. The router identifies that you are a new 'user' on the network and puts your IP in a restricted access mode. Any request you make over the network is redirected to the login page. Once you complete the login/confirmation process the router will allow your requests to go to the intended destination (e.g. Google). So what you are asking is possible, but comes with several caveats. I know my router allows me to create guest access and will direct users to a login page. But, that page is controlled by the logic in the router's firmware. I.e. I don't control the look and feel of the page and it only checks for a global password that is set through the router's firmware. What I think you need is the ability to have the router redirect the user to a custom page you create so you can authenticate users via parameters you choose (e.g. verify the users identity from a separate database). My router my have that capability, but I don't know and don't care to investigate. If you are using an off-the-shelf router you will want to hit up the manufacturer's site to see if this capability exists.
  13. "How" are the files being accessed through the player? Are the files being accessed directly such as mysite.com/mp3s/somefile.mp3, or are they being accessed through an intermediary page such as mysite.com/playmp3.php?id=22? If it is the latter then you can just add code to the page that fetches the mp3 to also update metrics around those requests. E.g. how many requests, when, by who, etc. Basically you can track anything that you want to track as long as you have that data. I.e. you can track who is playing certain files if you have a login system (or you could at least track by IP, although it is a poor approximation of an individual). If the files are not being accessed through an intermediary page, you have some options: 1. You can create an intermediary page and use that instead of allowing them to access the files directly. This is a good idea anyway. 2. You could implement AJAX. But, this seems like a lot of complexity for what you are wanting to accomplish 3. There are server-side logs. Depending on how (and with whom) you are hosting your site, your level of access to those logs may differ. My host gives me access to my logs through a web interface for manual inspection. but, I also have direct read access to the files. So, I could build my own code to parse that data if I wanted. Although this would likely only include IP address and files accessed.
  14. Most likely your query is failing. The error is telling you that the method fetchColumn() is trying to be executed against a non-object. In that line of code there is "$odb->query()" being used to execute a query and then "->fetchColumn(0)" is attempting to be executed against that result. If the query fails there is nothing for fetchColumn() to execute against. You have no error handling in that code. IMO, you should never assume queries will pass. You should always include error handling to at least provide the user some feedback. Although you would never want to dump raw error messages to the user in a production environment, just do something such as "a problem occurred, please try again later". But, you can either check for those errors and log them or echo them out in a non-prod environment. I also don't think that running "code" within HTML is a good idea, makes maintainability more difficult. <?php $result = $odb->query("SELECT `Tab` FROM `SiteConfig` LIMIT 1"); if(!$result) { $title = "Unable to retrieve title"; //Add additional error handling to get the real error info } else { $title = $result->fetchColumn(0); } ?> <title><?php echo $title; ?></title>
  15. If the first word is unique in all values, I would just convert the array to use those as the index for each item to keep the association tightly coupled: $colors = array("red hello","green this","blue lovely","yellow morning"); $newColors = array(); foreach($colors as $towns) { list($id, $value) = explode(' ', $towns); $newColors[$id] = $value; } print_r($newColors); Output Array ( [red] => hello [green] => this [blue] => lovely [yellow] => morning )
  16. No. There should be zero dependency on how you GET the data and how you DISPLAY the data. That is why I built the display function to take an array as a parameter instead of passing the DB Result object. If you pass the object, then the display functionality would be dependent on how you are storing and getting the data. I.e. if you change to PDO then the process of using that data in the function would have to change. You want to separate logic to reduce dependencies. You should reduce the process of getting the DB results and putting into array into a single function/method. Then when you change the manner in which you store or retrieve data you only need to modify that function/method.
  17. Well, that was helpful. If you aren't even going to put forth the effort, I don't know why I bother, When I am feeling generous I do test code before posting. But, in this situation it requires a specific DB setup and I am not going to go to that trouble just to test some code to work out some minor errors. I did all of that on-the-fly and I stated as much. Did you look at the HTML source? WHat has changed?
  18. $recCount = 0; //Create entity output $output .= "<tr>\n"; foreach($entityData as $data) { $countyCount++; //Open new column, if needed if($recCount%$recPerCol==1) { $output .= "<td valign='top' width='{$colWidth}%'>\n"; } The code is incrementing the variable $countyCount and that condition is expecting $recCount. Change $countyCount++; to $recCount++;
  19. @Richard Grant, he already stated he doesn't care about the users with access copying the audio - only that he wants to limit who can access. A simple password protected access model should work fine. @EricBeaudoin, I don't know squat about Joomla. S, if this is a specific Joomla issue I can't help you. But, it may not be a Joomla issue. there are a couple of things to verify first. You say that it works with the first value but not the second. Is this with the .htaccess restriction in place? I have to assume not. The $host parameter would seem to indicate the value of $file is the web address from the user's browser to the file rather than the file system location on the server. If that is the case, that may be part of the problem. You are putting the psp.php file in that same directory - which you are trying to limit access to. Put that file in another location that is not restricted. There are a lot of different things going on here with PHP, file locations, JavaScript, etc. You need to take a systematic approach to finding the problem. I "assume" that the original value is the "web" location to the file rather than the file system location from the server (based on the fact that the first parameter is $host). But, one should never assume. So, echo $file to the page to verify exactly what it contains when it is working. You should be able to copy/paste the value into your browser address to directly access the file (once you remove the .htaccess restriction). Once you have verified that is indeed what the value contains, change it to instead point to the psp.php file and echo it to the page. Then, copy/paste that value into your browser to ensure the file is being called correctly (change it to just echo a statement). Once you have verified, that $file is pointing to the correct script and the script is executing, change the script to "load/read" the mp3 files. Test the functionality by directly calling the script. Once that is all working, then call the file through the above code and see if it works. If so, put the .htaccess restriction back on the folder and test again.
  20. This absolutely is possible. I have a working script for this, but might take me a while to find it. However, I have no knowledge of Joomla so YOU would need to figure out how to make it work. The key is you would put the MP3 files in a directly that is not publicly accessible. You could use .htacxcess, but I like using a non-public folder. Anyway, all requests for an MP3 files will be through a URL such as mysite.com/playmp3.php?id=123 where the parameters on the URL identify the MP3 to be played. I built this to pass the ID of the database reocrd associated with the MP3 file, but you can tweak that as needed. You can put logic on that page to check if the user is logged in. If no, kick them to another page. If yes, get the file path to the file and read() the file and pass the result to the user. You can even create playlists that use these URLs and they will play in your MP3 player just as if they were on your PC.
  21. I used your exact wording (which I wouldn't use) and did a Google search: "PHP how long it takes for the page to get built" and lo and behold the fourth result provided an answer to what you are looking for.
  22. I see what you mean. I could have been more clear. What I was trying to state was that the possibility of collisions within that space of permutations is so infinitesimally remote that the discussion of whether they are an issue or not for passwords is not even worth discussing. And, trying to even use collisions for the purpose of cracking a password would be a foolish endeavor. I don't see the point. Are you thinking that storing it in this way will trip up someone trying to brute force the values? I guess that is a possibility, but think about "who" you are trying to protect the data from. This would be people with decent technical skills. Assuming you are already using a good hashing method, these would be people that have enough knowledge to reverse engineer the hashing method to create the logic to run a brute force attack. Do really think this type of person would not recognize that the hash is stored in binary and just add that to the brute-force process? I would run off the assumption that a person who has infiltrated my DB has likely accessed the source files as well. And, in that case they can "see" that the values are stored in binary. All this does is add a small level of obfuscation. And, obfuscation does not equal increased security in my opinion.
  23. Was that in response to my post? I was agreeing with you. Perhaps it is you that is confused. I specifically stated that collisions were a non-issue with respect to passwords. The collisions are only an issue when using a hash for something such as a checksum where an alternative file could be created to appear to be the target file with potential malicious modifications, and yet produce the same hash. It is not an easy thing to do, but it is possible. Again, I was just elaborating on your previous comment.
  24. To elaborate: MD5 hashes are commonly used as a checksum on files so you can verify the file you just downloaded has not been tampered with from what the original provider intended (e.g. someone has inserted a virus). It is in this context that collisions become an issue. With a large source it is possible to create another file with the same size which would produce the same hash - defeating the purpose of a checksum. With the "relatively" limited number of possible password combinations that could be produced with 8-40ish of the available characters, I would guess it is a safe bet that no collisions would exist in that range.
  25. There are a lot of problems with that code, the least of which is not getting the 'count'. 1. Don't use the mysql_ functions - they have been deprecated a long time. Use either mysqli_ or PDO 2. YOu are completely open to SQL injection 3. No need to check for $_POST['submit']. You are only interested in the 'type' so just check for that. Or, where there are multiple values being submitted, you should check the request method. 4. You're not checking for errors As to your specific request, you are defining $month from the exploded string of the last modified date, and then you define count from the mysql_num_rows() of $month. That makes absolutely no sense. mysql_num_rows() is used to count the number of rows of a database result. If you don't want the data and only need a cont - then query just the count and not the data. I think what you really want is the data count broken out by year and month. Start with this: <?php if(isset($_POST['type'])) { $type = mysql_real_escape_string($_POST['type']); $query = "SELECT YEAR(last_modified) as year, MONTH(last_modified) as month, COUNT(id) as count FROM leads WHERE lead_customer ='{$type}' GROUP BY year, month ORDER BY year, month"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { echo "Year: {$row['year']}, Month: {$row['month']}, Count: {$row['count']}<br>\n"; } } ?>
×
×
  • 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.