-
Posts
261 -
Joined
-
Last visited
Everything posted by Stefany93
-
Oh, too bad. I hope more people express interest in the future. Writing tutorials help both and writer and the reader improve, so I think it is nice.
-
I plea the leaders of this forum to put a "Tutorials" section where users can post programming related tutorials with the purpose of educating their colleagues.
-
Yup, the (*) operator is messing up your results, like the colleague above said. Never use the * to fetch everything from the DB because it makes it run way slower and if you add more columns you would need for special occasions only, and you fetch 'em all at every query, that will slow down your application greatly.
-
Glad I could help. Usually, I will avoid nesting functions like hell because a) it makes the program run slower, kills readability and some functions work while nested within another and some don't which can drive ya crazy. Better approach will be: if(isset($_POST['field_name']) and !empty($_POST['field_name'])){ $field_name = trim($_POST['field_name']); } Now, in the past, when I was green, I would use $_POST['file_name']; without assigning it to a variable like $field_name which proved to be stupid because if at any time you want to change the name if of the input field you are fetching the information, then you'd have to change tens of $_POSTs in your code. The same in JavaScript. If you have like <h1 id="main_header"></h1> and you want to fetch it with document.getElementById('main_header'); it is better to put in a variable like this var main_header = 'main_header'; and you wouldn't have to worry about the ID being changed. You could just then change a single variable.
- 5 replies
-
- help
- blank field
-
(and 1 more)
Tagged with:
-
Using var in front of JS variables ensures: 1. That you are following a good programming practice; 2. The creation of a scope of the variable (As Josh above pointed out); 3. Better readability, since seeing var in front of a variable automatically means that this is the first instance of this variable and you are not over-writing another one; 4. That you are a good programmer; Kind of like my in Perl, although not that strict in relation to the scope. I wish they had made var mandatory in JS just like my had become in Perl 5.12 + Do something, Mr Eich!
-
Good approach, but what I usually do when I write a validation script is that I declare a new array like this $errors = array(); and I append the array with any errors that arise and before doing what you wanted to do with the DB (Insert, Select, Update, whatever) I check whether the $errors array is empty, i.e. whether the validation script gave any errors. If it is empty, execute the query, if not, display the $errors array with a foreach loop to let the user know where he went wrong. And instead of $_POST['field_name'] == null, you can also use the negated empty() function like this !empty($_POST['field_name']) And of course, make sure you escape all use input. Vital rule in programming - all user input is considered malicious unless proven otherwise.
- 5 replies
-
- help
- blank field
-
(and 1 more)
Tagged with:
-
Yeah man, you need to populate your table in order to fetch the data needed for the array. And undefined offset almost always means that you are trying to access an un-existing element of an array. Like an accessing $array[3] while $array having only 2 elements will generate the same error.
-
If the OP wants to learn how to do it, using a premade script will be a mistake. Even if he wants just to use something ready, it will be a mistake again. Pay a programmer $30 to make a reg script for you, those "premade scripts" are ancient and full with security holes. And if your website is not very big, I'd suggest using SQLite over MySQL.
-
Howdy folks, After diving into Perl, I managed to write my first "program" or script rather. Basically what I wanted to do was to create an equivalent of the PHP function print_r() for displaying arrays' keys and values and thus helping for an easier debugging. Here is the script: #!/usr/bin/perl # We are telling Perl that # we shall be working in a web # browser and therefore sending # the proper HTTP headers. print "content-type: text/html \n\n"; # Perl version. use v5.16.3; # This subroutine will display # the keys and the elements # of the array # given as a subroutine parameter. sub print_r(){ # $x will iterate through the # @keys array. my $x = 0; # We collect the keys of # the given array in the # @keys array. my @keys = keys(@_); # Display 'Array' before the loop. print 'Array ( <br />'; # Iterate through the array. foreach my $value (@_){ # Print the key of the current value # using $x as an index starting at 0 # and then print the value. print ' ' . $keys[$x] . ' => ' . $value . ' <br />'; # Increment our index variable so that # the next element of the array is selected # in the next iteration. $x++; } # End of the loop. Dislaying the closing the array. print ' )'; } __END__ I have a couple of questions if you guys can help me please! 1. Shall I leave the comments as they were within the subroutine or put them above it? 2. I tried to check whether the parameter is an array with the ref() function, but the problem is that Perl subroutine parameters treats everything as an array, even empty string or a scalar variable as long as it is put as a parameter in the sub call. So I can't really think of a proper check that checks whether for example &print_r(@array) is an array. If any of you can think of tips to give me for Perl, I will be very grateful. I think Perl is an awesome language.
-
Is sha512 an acceptable encryption algorithm for passwords?
Stefany93 replied to DeX's topic in PHP Coding Help
SHA512 is the best hashing function so far in my opinion. Just remember to always salt your passwords before storing them, even after hashing them. No matter what they tell you, without salting your hashed passwords are just a little more secure than plain text. -
I am sorry, but just because you use these frameworks doesn't mean that everyone who do not use them are stupid like you are trying to imply. You are just another soldier in the "we use frameworks" army. I am a soldier in the "we do not use frameoworks " army Let's keep it civil...
-
Super simple URL rewriting tutorial with .htaccess
Stefany93 replied to Stefany93's topic in Apache HTTP Server
Well it is too late to move it now by myself. -
Super simple URL rewriting tutorial with .htaccess
Stefany93 replied to Stefany93's topic in Apache HTTP Server
Sorry, I was searching for the correct category and couldn't find one If a moderator is so kind as to move the topic that will be great. Thanks for the update. -
Note: This article assumes you have a basic understanding as to what .htaccess files are, how they work and how to create one. And that you know how to use regular expressions. When we were green programmers, we would create a website with these files: index.php about.php contact.php And when our visitors wanted to access a certain web page within our website, we would provide them with links to these documents directly like this: www.example.com/about.php However, all this above turned out to be the wrong way for many reasons. First of all, referencing web pages with their full name is not very secure because an evil user would know (a where "about.php" is located, b) that it is a PHP file and that will facilitate his work to ruin our website. The correct way to fix this is with a .htaccess file placed within out root directory where our website resides. Before you use your .htaccess file to re-write an URL, make sure your server a) supports .htaccess files because some bosses of hostings forbid them for God knows what reasons and b) that even if the hosting allows .htaccess files, you might need to contact the hosting people to ask them to configure their server to accept URL re-write on a per directory basis. Now we would want to turn this URL http://www.example.com/about.php into http://www.example.com/about Our very first directive must be: RewriteEngine On # We are turning on the rewrite engine on our server Some hostings require you to specify as to from where the re-writing shall begin. Let's say you store all of your website files and folders in your root directory. Then your second directive will be: RewriteBase / # We shall be re-writing files in our root directory. When testing on localhost using the "RewriteBase" directive will give a server error. Our third directive: RewriteRule about about.php Now, golden rule - when re-writing a URL, you must first specify the RewriteRule directive and then the word right after that is the word that rewrites the name of the file whose name you want to re-write. So RewriteRule about means that the word that will come after "about" is the one that will henceforth be known as "about" in this case about.php So: RewriteRule about about.php # Re-write the file name about.php to about So when we write in the URL http://www.example.com/about the server will actually be pulling the information from about.php but the user will never know! That will be our little secret! Now the problem with the above approach is that the re-writed name is not spesific. Meanning that "about" will match any URL that has the word "about" in, for example: http://www.example.com/aboutmyawesomepizza The above will be matched. We do not want that. We can solve this problem with regular expressions: RewriteRule ^about/?$ about.php Super! Now our URL will only match http://www.example.com/about with or without trailing slash, does not matter. One last thing - we want about URL to be case-insensitive so that http://www.example.com/about and http://www.example.com/AboUt will both match the about.php file. We do that by putting the [NC] flag at the end of the directive like so: RewriteRule ^about/?$ about.php [NC] "NC" meanning "no case". I also thought it meant "North Carolina" but sadly it did not. All directives put together: RewriteEngine On RewriteBase / RewriteRule ^about/?$ about.php [NC] More reading: What are .htaccess files? - http://httpd.apache.org/docs/2.2/howto/htaccess.html RewriteRule directive - http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriterule
-
Awesome book indeed, I have been reading it for some time now seriously. What I mostly like about it is that they actually "talk" there, while in the other programming books, they only show you tons of code with very little explanation on what to do now or how to use the code they have shown.
-
Which PHP Editor do you think is the best? [v2]
Stefany93 replied to Daniel0's topic in Miscellaneous
Notepad++. I get a little jealous when using IDEs because I want to write all the code by myself