Jump to content
Larry Ullman's Book Forums

Necuima

Members
  • Posts

    359
  • Joined

  • Last visited

  • Days Won

    7

Everything posted by Necuima

  1. Thank you again for the advice. Yes, we're getting by here too - thankfully still in remission! I am going to try and set the lifetime of the member area cookie as well as the lifetime of the associated session. It is best to use 'ini_set's or the session_set_cookie_params as per page 361. Is there a 'session_set...' PHP function for the session maxlifetime? If 'ini-set's, do they come before the session-start()? For the admin area I'm not so concerned as I'm the only one with a password (SHA encrypted) to get in there and I always logout which destroys the session and its associated cookie as per your guidance in the book. Or am I under a security mis-apprehension? Cheers.
  2. Hi Larry, Thanks for the advice. As you can probably guess, the background to the question is as follows: . I have a website which has both a public area and also a member's area. . member's sometimes forget to log out of the member's area when they are finished. . But, if I understand your advice correctly, even if they forget to log out, another person on a different computer could not use that session data as they won't have the corresponding cookie on their PC - is that correct? The website in question also has an administration area. I have added your 'session agent' advice (pages 368...) as I don't want any malicious person messing around in that admin area! Thanks again for your advice and I hope and trust that you and your family are A-OK. Best wishes from Oz.
  3. Hi Larry, Haven't been on the forum in a while, but hello from Oz. I have been more 'knee-deep' into jQuery lately. On pages 360... you describe setting the lifetime of a session cookie. Is it correct that when the cookie 'dies' that the session data are no longer in existence or accessible? Also, is the 'session_set_cookie_params' needed on every script that uses the session? Thanks in anticipation for your advice. Cheers
  4. Hi Rui, Sorry that I did not get back to you sooner. For some reason I cannot copy and paste code into a reply such as this without typing it all in line by line. If you ask Larry for my email address, it's OK if he lets you know what it is and then you can email me and I can attach the code in a reply. Cheers, Necuima
  5. Trying a drag and drop... No - that doesn't work either.
  6. Hi Larry, The reference is from page 32 of the book - I think I've got the first edition - sorry if I've posted this in the wrong spot. I am seeking advice on heredoc best practices. Here's an example that I've been experimenting with: The scenario is a program to edit the information about an item whose details have been retrieved from a database via a standard MySQL select. The data get loaded into an HTML form with the variables from the database interpolated into the form. There appear to be two approaches: 1) to have most of the form HTML with the database data added via <?php echo $var; ?> with any number of these echos. Or 2) heredoc echo the whole form thus avoiding the need to have all the PHP insertions. I have tried both approaches and they both work fine. The second approach looks 'cleaner' to me, but I'm wondering if it's "bad coding form"? Thanks in anticipation for your thoughts or any other forum member's thoughts. Cheers. P.S., the updated from data get processed via PHP Redux.
  7. Hi Larry, When I try and paste into the post, nothing will paste. I tried within code tags and with no code tags. I tried with right click paste and nothing pastes. I tried with the past button on top of the post box, but again, nothing pastes. There is no error message. My environment is IE11 within Windows 7 64 bit. Thanks.
  8. I think this is the same issue that I have - trying to paste code into a forum post such as this one. Thanks, Necuima.
  9. OK, I think that I understand what happens. 1) mysqli_fetch_row returns an array of strings - according to the w3schools manual which in my case get loaded into the PHP variables via the list. 2) in the php.net manual re arrays, it says "strings containing valid integers will be typecast to the integer type cast" So while my MySQL data type is a tinyint, the mysqli_fetch_row returns its value as a string, but then that string is converted to an integer when it is inserted into an array as a key. Please let me know if I've got it correctly. Thanks.
  10. Hi Larry, On page 493 you describe the list() function as well as its use in combination with a 'while' loop from a database select. I have used this successfully innumerable times but I don't understand the following: while(list($var1, var2, var3) = mysqli_fetch_row($result)) .... The $var1, $var2 sources are in the database as tinyints, length 1. Yet if I do a vardump on the results of the list ($var1, $var2) they are strings, length 1. Yet one can use those values as numeric array keys? Can you please help me understand what's going on here? Many thanks, and as always, Cheers from Oz.
  11. Ahhh - many thanks - works like a treat! Re my other question re pasting code to the forum between the code and closing code tags - should one be able to do this? Thanks, and Cheers
  12. P.S., I tested the content of the $title_array array with print_r and it contains what I expect it to contain. Also tried without the double quotes - i.e. title=$title_array[1][1] but it still gives the same error. 'Tis a mystery. Cheers
  13. Further to the above, when I try and use an array, I get an 'array to string conversion error' which is not there if I use a dynamically generated variable. The test code is (within a heredoc echo): <tr> <td><a href="$large_1_1", title="$title_array[1][1]"><img src="$icon_1_1</a></td> <td><a href="$large_1_2", title="$title_1_2"><img src="$icon_1_2</a></td> </tr> The array variable for the first title gives me the error, the dynamic variable for the second title works fine. Can you see what I'm doing wrong with the array approach? And this post facility won't let me copy and paste code between the and tags. Thanks in anticipation for your insights. Cheers Oops I missed the closing quotes and '>' in the src-es - they are there in the code.
  14. Hi Larry, Nice to hear from you. Yes, I first tried to use an array construct but the heredoc echo I am using would not resolve the array elements. Then I tried creating the PHP variables one by one and while that worked it was cumbersome. I think I found the dynamic variables info in stack overflow almost by accident but I can't remember exactly (I'll put that down to my septuagenarian years :-) Again, cheers from Oz.
  15. Hi Larry, I haven't been on the forum in a while - what I have learned from your books so far has kept me going nicely. But I needed to create a whole slew of PHP variables with similar names and came across the ability to create them dynamically. In case it is of interest to forum readers, here's my code (from a MySQL select result): while (list($var1, $var2, $var3, $var4) = mysqli_fetch_row($result)) { ${"title_" . $var1 . "_" . $var2} = $var3 . ", " . $var4; } This creates PHP variables of the form $title_n_m where 'n' will be the value of $var1 and 'm' will be the value of $var2. Works like a treat - I was quite amazed! All the best from Oz, Cheers.
  16. I can't see how to edit my post - that should have read "conditionally 'requires'", rather than "optionally 'requires'". Sorry.
  17. Hi Larry, It's been a while since I've visited the forums so I hope that all is well with you. I have a question that you have already answered on page 51 and that is to do with the closing ?> The context I have is some php code that optionally 'requires' a php function which is the only thing in the .php file being 'required'. Is there any difference that the .php file which is the function is being optionally 'required' versus just 'required' in the normal code stream? The php file with the function does have the opening <?php tag but it is being included within a php code stream. Should I have the opening tag in the function 'include'? Originally I had the closing ?> in the function code and that worked fine in my development environment, but caused the error message in the production environment. My development environment is Windows 7 with xampp providing localhost. Many thanks in anticipation for your advice, or that of any other forum member. Cheers from Oz.
  18. Hi, Here's a simple example of using 'in_array': // Validate the type. Must be jpg. $allowed = array ('image/jpeg', 'image/pjpeg'); if (in_array($_FILES['upload']['type'], $allowed)) The $_FILES is just a super-global, so the test checks to see if the upload type, which is just a variable, is in the $allowed array. Hope it helps.
  19. Hi Larry, Yes I've been doing that as you have correctly surmised :-) Thanks, and Cheers from Oz.
  20. Hi, I am following the file upload process (pp 427 .....), a process I have used many times before A-OK. I am using the procedure to upload mp3 files but sometimes when I check the mime type, it is blank, thus the upload does not proceed, even though that same file will play perfectly in Windows Media Player. Can anyone shed any light on this? Any advice will be most appreciated and thanking you in anticipation. $allowed = array ('audio/mpeg', 'audio/mp3'); if (in_array($_FILES['upload']['type'], $allowed)) { // MIME type OK // now move/upload the new music file $music_file_name = "../music/music_" . $key . ".mp3"; if (!move_uploaded_file($_FILES['upload']['tmp_name'], $music_file_name)) { // move/upload was not OK // print a message based upon the error. etc.... P.S., My environment is Windows 7, 64 bit with Apache, PHP and MySQL.
  21. Hi and welcome to the forum. I don't have this particular book but you should be able to see what the AJAX call can return from the code in login_ajax.php. From your code the response from the AJAX call can be either 'CORRECT', 'INCORRECT', 'INCOMPLETE' or 'INVALID EMAIL', so not a Boolean. You can make an AJAX call in several different ways; this one is via 'GET' and an object named options supplies the information to be sent to the login_ajax.php script. There are lots of guidance on AJAX via Google as well as the valuable information in Larry's books. Bottom line an AJAX call invokes a script (login_ajax.php in this instance) without leaving the web page you are on. The callback function then processes the returned data from called module (login_ajax.php in this instance) but it processes it in the web page you are on. You can see DOM elements being updated by the callback function, e.g., where 'You are now logged in!' is being inserted into the DOM. The code you have posted is using jQuery and there are lots of information on that too available. jQuery, used correctly, is a fantastic tool. As I don't have this particular book, I'm sorry that I can't help more. Best wishes.
  22. It looks like the closing bracket is missing in your include statement. Cheers
  23. Hi, In Larry's book, PHP & MySQL for Dynamic Websites, on page 90, he has a good explanation: "As a best practice, use the ./filename syntax when referring to files within the same directory as the parent (including) file, ... A file stored in a directory above the parent file would be included using the path ../filename, and a file stored in a directory below the parent file would use ./directory/filename". You can also go up (../) and then down again if necessary - e.g., ../next_level_up_directory/then_down_from_there_directory/filename. I believe that they are referred to as 'document relative paths'. Hope it helps, Cheers.
×
×
  • Create New...