Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
Well, any salt is better than no salt. But, if you are going to salt, then the salt should not be a "constant" and/or based on the password itself. Although the salt in the above function would be variable, because it is based upon the password it would be a trivial exercise to brute force ALL the hashed passwords at one time. For example, if two users had the same password, the function above would produce the same hashed value. So an attacker only needs to crack one to get both values. A better approach is to use some piece of data that is unique to the user but which would not change. That way an attacker would have to brute for each password individually. Examples would be user ID, a timestamp of when the user signed up, etc. Then change the function to accept both the password and the salt. function smhs($password, $salt, $algorithm="sha256") { return hash($algorithm, $salt. $password); }
-
I think daylight savings time screwed up my little function
Psycho replied to dadamssg87's topic in PHP Coding Help
Well, you are certainly doing it the hard way. No need to use strtotime() on the start data and then add a numeric value to it. strtotime() can easily add days to a date using "+n days". Anyway, to solve your problem, just set the start date to noon, $start = "2011-11-06 12:00:00"; $num_days = 6; for ($day = 0; $day <= $num_days; $day += 1) { $stamp = strtotime("{$start} +{$day}days"); echo date('l - n/d/Y - h:i a',$stamp)."<br/>"; } -
If you want help with your homework you need to at least make an attempt. Then if you have a problem, show the code you have written and what your expected results are and what the actual results are.
-
Passing array to textarea so that it's formatted (line breaks)
Psycho replied to VFDinc's topic in Javascript Help
Moved this to the JS forum,but really this could be solved many different ways. The easiest is to simply to add a line break in the values. $OppStats = "Name:{$Name}\nClass: {$Class}\nLevel: {$Level}"; -
This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=347622.0
-
Here is a real-world example. Let's say you don't salt your passwords and a user, unfortunately, uses a simple password, such as "password". That person's MD5 has would be: 5f4dcc3b5aa765d61d8327deb882cf99 There are people who have constructed massive tables of the MD5 hashes for known values. So, they could simply go here (http://md5decryption.com/) and enter the hash to find the value. Although there are an infinite number of values that could create that hash, there is a finite list of strings that can be passwords which is why this works. If you use a salt, then the "bad guy" would need to know the salt and the hashed value. Then he can create a script to start going through the massive list of potential passwords in order to find a match (brute force). When doing this the person would start with normal "words". That is why you should always use complex passwords. Even if your hash and salt were compromised it could take a long time to find the correct hash. This is also why you would want to use a different salt for each user. That way the "bad guys" couldn't create a new rainbow table to use against all the users' hashes. They would have to brute for each and every hash separately.
-
Forms: Input fields stop working after sending empty strings
Psycho replied to bunder5's topic in PHP Coding Help
Not without seeing the code. What do you mean - exactly - by "it will stop accepting values when I resubmit". Have you done a print_r($POST) to help debug the issue or done any debugging at all? -
You do realize that the person you responded to in your last several esponses is a different person, right? Personally, I agree with xyph that you are half assing it and it is a bit rude to ask for advice and then to dismiss the advice you are given. I never said you had to rewrite all your code from scratch. You already have much of the "micro" logic needed - the problem is the "macro" logic - in other words the overall flow. All you need is a simple flowchart of how the logic should be. You can then re-use most of the code you already have. . . . or you could just continue to tinker with it.
-
Yes, it is possible. I'm not sure of the exact process involved, but I've tried out a couple scripts in the past. I "think" Jinzora will do that as well as allow users to manually search and play music - but you could probably turn that part off somehow. It is an open source PHP application, but I don't think it has been updated for years. Here is a list of other potential solutions, but I can't attest to their quality. I just did a google search for "PHP Live streaming": http://www.hotscripts.com/category/scripts/php/scripts-programs/multimedia/streaming-and-broadcasting/
-
You don't have that much code! You should never "tinker" with code in the hopes of getting the results you want. That is a recipe for disaster. If you don't "know" what your code is doing and why you will likely have bugs that you don't even know exist.
-
As I said, you should work out the logic on paper - THEN write your code. I would think the logic should go somethign like this: if(isset($_POST['Quick Pick'])) { //Dynamically define user picks } else { //Define user picks from POST data } //Validate that user picks are valid (could be invalid if user did not use quick pick) if($userPicks) { //Compare user picks against lottery picks }
-
If the quick pick field is a checkbox, then yes, you can just do an isset check. I would do in if/else. If quick pick is selected determine the picks programatically, else use the selections the user selected. THEN, after you have determined the user selections, you would compare against the lottery selections. It looks like you are only comparing against the lotter selections if the user did a quick pick. If you are not getting the results you expect, echo the pertinent variables to the page to verify that the values are what you expect. I think you really need to pull out a sheet of paper and figure out your logic, then go back and code it. The flow of your code seems pretty haphazard. For example: if (isset($_POST['Quick Pick'])){ if (count($_POST)>0) { What is the second if() condition for? If the first condition is true, then the second conditions will always be true.
-
You need to put quotes around your values 'inside' the query. When your query fails it is helpful to echo it to the page. The complete query SHOULD look something like this INSERT INTO clients (companyName, address1, address2, city, province, postalCode, phone, email) VALUES ('big company', 'big bay #8', 'some big warehouse', 'big city', 'T1T0N0', '0123456789', 'bigKahuna@bigKahuna.edu') Yours currently looks like this (note, no quotes around the values. INSERT INTO clients (companyName, address1, address2, city, province, postalCode, phone, email) VALUES (big company, big bay #8, some big warehouse, big city, T1T0N0, 0123456789, bigKahuna@bigKahuna.edu) Change your query definition to this $query = "INSERT INTO clients (`companyName`, `address1`, `address2`, `city`, `province`, `postalCode`, `phone`, `email`) VALUES ('{$companyName}', '{$address1}', '{$address2}', '{$city}', '{$province}', '{$postalCode}', '{$phone}', '{$email2}'"; EDIT: Added province (credit to elkyn)
-
Nope if (($handle = fopen("http://www.website.com/images/uploads/Recruitment_for_Web.csv", "r")) !== FALSE) { // format the date first format_date($data); // Next we sort the table by date uksort($data, 'mydatesort'); while (($data = fgetcsv($handle, 10000, ",")) !== FALSE) { How can you run format_date($data) before you have even defined $data? $data, in that code, represents one record, so you couldn't run the format_date() function on it anyway. Also, why would you use uksort() with global $data; in the sorting function so you can compare the values? Just use usort() and don't use global(). Plus, the OP never stated he wanted to change the format of the displayed date.
-
OK, I just read through your code a little bit and see you are doing something similar, but I'm confused as to what your problem is. What is it that is not working as you want it - you have several if() statements, so not sure which one you are even referring to.
-
I'm not even going to read through your code. There is a very simple way to get a random pick from a fixed set of numbers using only a few lines of code (aside from defining the available numbers and the number of items to choose) and no loops. I'm not sure I understand your numbers though. I see this $intMaxReg = 59; $intMaxPB = 39; Is that supposed to meant the the 'regular' numbers can be from 1 to 59 and the powerball can be from 1 to 39? That doesn't make sense to me based upon how I understand the powerball lottery to work - which is the powerball can be any number in the total range. So, based "my" understanding I would do this to get a random pick: //Create an array from 1 to $intMaxReg $numberRange = range(1, $intMaxReg); //Randomize the array shuffle($numberRange); //Get 6 numbers from the array $quick_pick = array_slice($numberRange, 0, 6); //Use the first or last number as the powerball If the powerball really is supposed to be limited to only 39 while the rest of the numbers can be up to 59, that is easy enough to do as well. Would just need to know if the powerball selection is separate from the regular numbers. E.g. if the powerball is 5, can 5 also be selected as one of the regular numbers.
-
I went ahead and tested against some mock data and found a couple issues. This is fixed and should work if your data is in the format you say it is: //Function to add timestamp (and remove hours from date) function addtimestamp(&$record) { $record['timestamp'] = strtotime($record[0]); $record[0] = str_replace(' 00:00:00', '', $record[0]); } //Function to sort array function sortbytimestamp($a, $b) { if ($a['timestamp'] == $b['timestamp']) { return 0; } return ($a['timestamp'] < $b['timestamp']) ? -1 : 1; } //Define the source of file $fileSrc = "http://www.website.com/images/uploads/Recruitment_for_Web.csv"; //Read file into an array $data = file($fileSrc); if($data!=false) { //Add a timestamp value to each record array_walk($data, 'addtimestamp'); //Sort the array using custom function usort($data, 'sortbytimestamp'); //Output the data echo "<table border='1'>\n"; foreach($data as $record) { $link = (!empty($record[7])) ? "<a href='{$record[7]}' target='_blank'>{$record[5]}</a>" : $record[5]; echo "<tr>\n"; echo "<td>{$record[0]}</td>\n"; echo "<td>{$record[1]}</td>\n"; echo "<td>{$record[2]}</td>\n"; echo "<td>{$record[3]}</td>\n"; echo "<td>{$record[4]}</td>\n"; echo "<td>{$link}</td>\n"; echo "<td>{$record[6]}</td>\n"; echo "</tr>\n"; } echo "</table>\n"; }
-
This is not tested, so there may be some syntax or minor errors, but the logic is sound //Function to add timestamp (and remove hours from date) function addtimestamp(&$record) { $record['timestamp'] = strtotime($record[0]); $record[0] = str_replace('0:00:00', '', $record[0]); } //Function to sort array function sortbytimestamp($a, $b) { if ($a['timestamp'] == $b['timestamp']) { return 0; } return ($a['timestamp'] < $b['timestamp']) ? -1 : 1; } //Define the source of file $fileSrc = "http://www.website.com/images/uploads/Recruitment_for_Web.csv"; //Read file into an array $data = file($fileSrc); if($data!=false) { //Add a timestamp value to each record array_walk($data, 'addtimestamp'); //Sort the array using custom function usort($data, 'sortbytimestamp'); //Output the data foreach($data as $record) { $link = (!empty($data[7])) ? "<a href='{$data[7]}' target='_blank'>{$data[5]}</a>" : $data[5]; echo "<tr>\n"; echo "<td>{$data[0]}</td>\n"; echo "<td>{$data[1]}</td>\n"; echo "<td>{$data[2]}</td>\n"; echo "<td>{$data[3]}</td>\n"; echo "<td>{$data[4]}</td>\n"; echo "<td>{$link}</td>\n"; echo "<td>{$data[6]}</td>\n"; echo "</tr>\n"; } } EDIT: It looks like the forum parsing messed up the value for $fileSrc, so just make sure you correct it before trying it. EDIT#2: I notice your logic for removing the hours from the display date only removes a single zero for the hour, but you stated that there are two zeros for the hour. I would also think you would want to removing the space before the time component. I used your same logic, but I would think the appropriate replacement would be $record[0] = str_replace(' 00:00:00', '', $record[0]);
-
No need to add 1 to the count, just use the correct comparison if (($count) % 3 == 2) But, better yet, you should make the number of records to separate a variable so you can change it by just changing the variable and not having to modify code. The same goes for the number of records to show. Don't hard code the 20, make it a variable. <?php $record_count = 20; $record_grouping = 3; for($count=0; $count<$record_count, $count++) { echo "<span><p><strong>$count</strong> Lorem ipsum dolor sit amet, consectetuer adipiscing.</p></span>\n"; if (($count % $record_grouping) == $record_grouping-1) { echo "<hr />\n"; } } ?>
-
Splitting a string on (only) the last instance of a needle
Psycho replied to stubarny's topic in PHP Coding Help
Once I had the target, I'd probably revert to string functions to get the other values since they would be easy to determine at that point. -
Find next session between two dates/times
Psycho replied to George Botley's topic in PHP Coding Help
I think you are making it more difficult than it needs to be. This should get you what you need. SELECT * FROM table WHERE end_time >= NOW() ORDER BY end_time LIMIT 1 If there is a current session, the end time would be past NOW(), otherwise it will get you the very next session. The only problem you would have is if sessions overlap and the session length can be different. -
Splitting a string on (only) the last instance of a needle
Psycho replied to stubarny's topic in PHP Coding Help
What was wrong with the last solution I provided? It was not very complicated and it worked. The only downsides were that: 1. It used preg_match_all and then used the last match. So, it was slightly inefficient in having to find, potentially, multiple matches. 2. For the capture it uses ([^"]+), which works perfectly for this particular use case. But, it wouldn't be portable. If I wanted it to be portable I would just change the match to be (.*?) between needle 1 and needle 2. Not efficient, but portable. This seems to meet the OPs requirements and is portable function findLastTarget($subject, $needle1, $needle2) { $pattern = "#{$needle1}(.*?){$needle2}#"; //$pattern = '#</span></a> <a href="([^"]+)" rel="nofollow"><span class=pn><span class=np>Next »</span></span></a></div>#'; $result = preg_match_all($pattern, $subject, $matches); if(!$result) { return false; } return array_pop($matches[1]); } $needle1 = '</span></a> <a href="'; $needle2 = '" rel="nofollow"><span class=pn><span class=np>Next »</span></span></a></div>'; $targetText = findLastTarget($subject, $needle1, $needle2); -
Did you read the page I linked to above that gave several different solutions? Again, none of them are perfect and each has particular benefits and drawbacks. So YOU need to make a decision on which solution works best for your site and then implement it. If you want someone to write code for you then you need to post in the freelance forum and see if someone is willing to do it (for $$). Forum rule #12 http://www.phpfreaks.com/page/rules-and-terms-of-service
-
The only PHP function that code is mysql_fetch_array and that function works in both PHP4 and PHP5. So, it is already compatible for PHP5. http://php.net/manual/en/function.mysql-fetch-array.php