Jump to content

ginerjm

Members
  • Posts

    6,906
  • Joined

  • Last visited

  • Days Won

    99

Everything posted by ginerjm

  1. But - you will want to turn off the ini_set in your production .ini file or your main menu script
  2. Actually neither of those changes should have mattered. It was just the proper way to code (IMHO). There must of been another change too. HTH! And glad to see my code being used.
  3. OK - the pdo connection logic (mine!) is showing nothing wrong. As for the mainline code - I don't see any problems other than your use of this: inet_aton('$ip') Is the "inet_aton" variable an array? If so you are using the wrong syntax. Indices need to be wrapped in [] not parens. Tip: Don't bury a query statement inside a function. Assign it to a variable and use that var in the function call. That way if you need to dump the query to debug it you can simply echo it. Here's how I would do it: error_reporting(E_ALL); ini_set('display_errors', '1'); $php_scripts = '../../php/'; require $php_scripts . 'PDO_Connection_Select.php'; require $php_scripts . 'GetUserIpAddr.php'; //******************************* if (!$pdo = PDOConnect("foxclone_data")) { echo "unable to connect"; exit; } $result = mydloader($pdo, $_GET["f"]); if ($result === true) echo "Success"; else echo $result; exit; //*********************************** function mydloader($pdo, $l_filename=NULL) { $ip = GetUserIpAddr(); if(isset($l_filename)) { header('Content-Type: octet-stream'); header("Content-Disposition: attachment; filename={$l_filename}"); header('Pragma: no-cache'); header('Expires: 0'); readfile($l_filename); $ext = pathinfo($l_filename, PATHINFO_EXTENSION); $stmt = $pdo->prepare("INSERT INTO download (address, filename,ip_address) VALUES (?, ?, inet_aton('$ip'))"); $stmt->execute([$ip, $ext]); $test = $pdo->query("SELECT lookup.id FROM lookup WHERE inet_aton('$ip') >= lookup.ipstart AND inet_aton('$ip') <= lookup.ipend"); $ref = $test->fetchColumn(); $ref = intval($ref); $stmt = $pdo->prepare("UPDATE download SET lookup_id = '$ref' WHERE address = '$ip'"); $stmt->execute(); return true; } else { return "No filename provided"; } } Questions Why are you reformatting the 'id' from one table to the other? Makes it hard to later connect/compare them. What is the inet_aton variable? You are not passing to the function so you should be getting an error message I think. I moved the connect call outside of the function and passed the handle as a function parameter. I added a result to the call to your function and eliminated the buried exit. And I moved the function to the bottom instead of the top. That way when one looks at the script they can see right away what is trying to accomplish (which I still don't see) without having to browse thru a lot of code. And I removed all of the excess spaces. No need for them. As well as the extra blank lines. That may have been caused by your editor when you uploaded it to here.
  4. Actually the readfile line would generate some output, no? You are correct about the db code tho.
  5. Since the error is in the connection script how about showing us that? (hide the credentials if present) PS - that connect script should not be sending anything out. If you have a message to be sent either exit right there or return it to the calling script and let that script respond (and exit).
  6. I too am happy to see this site come back alive. Twas a surprise and a bit of a let-down with no info forthcoming . Had to make do with another site which was also down at the same time but only for a couple of days. Of course (as I have posted elsewhere) things on PHP forums seem to be at a standstill - traffic is way down. Hopefully once this site finishes with its transition, things will pick up and those of us who like to come and be of some aid to those needing it can continue to get our fix.
  7. And how does your latest response resolve the issue? I told you how I would write it. But apparently my old-style way of coding that has worked for 40+ years is no longer the preferred way. I do fail to see how your sample does anything to improve security. Perhaps in that (unknown) function there is something about that but what we are trying to solve really has no relation to that. As you write more you may start to see the value in writing code that is easy to read and interpret. The sample you are showing us of the 'new way' of coding is NOT easy to interpret. Fact. So when you have to go back into this script a couple of years from now, are you going to readily remember what it is doing? Good luck with your progress. I"ll step aside now.
  8. So you are telling us that this line: bool $dog_error_message = $lab->set_dog_name('Fred'); is now giving you the message. I thought that was the problem originally. To me - not a version 8 user yet -I wonder why the elongated code. If the call to set_dog_name function is supposed to do something for you and you want to know it it succeeded or not, why don't you just put the call inside an if and do your 'things' from that instead of setting a variable and then checking it. Of course, I am assuming (!) that the function is expected to return a boolean value already (so why the typecast?) so the following code should work very well: if ($lab->set_dog_name('Fred')) echo 'Name update successful<br/>'; else echo 'Name update not successful<br/>';
  9. Are you using PDO or MySqlI? The former is the easier one to use. That said - read the manual under PDO to see how a query statement would look and then simply do it. Here is a very brief and simplified spot of code: // (write a function that makes your connection.) $pdo = PDOConnect($dbname); // this function also sets the db name $q = "select fld1, fld2, fld3 from tablename where fld1=:argument1 and fld3=:argument3"; $qst = $pdo->prepare($q); $parms = array('argument1'=>$myvalue, 'argument3'=>$another_arg); if (!$qst->execute($parms)) { // (handle the error and exit?) } //************* //(now process the query results) As you can see this is simpler than the way MySqlI uses binds and results to manage prepared queries. PDO simply asks you to put the needed :parms into the query and then to prepare it. Then you simply set an array with the values for those parms and execute it whenever you are ready to run the query. Note: you only need to make your db connection once in a script unless you are doing something that requires a 2nd connection (??). Call the connection function once to get a handle and then keep using that handle when you need to run any query. Don't put the connect call inside a function that gets called repeatedly. Simply pass the handle to the function as one of its arguments.
  10. OK - I see your text answers my first question. Now try removing the bool from that line. It appears now that you are trying to make an assignment. Since you don't want to change the type of the var $dog_error_message remove the bool from the statement. You might want to use that somewhere but I don't think you want it here since you are simply trying to copy one value to another variable. Would be silly to do that simply to get a boolean value when you are really trying to get the value returned from that function call, whatever it may be.
  11. What line number was in the message and are you showing us that line??? And what is that 'bool' at the beginning of the line with your var in it? Is that something new to ver 8? Try removing it.
  12. More - If you know how your csv file is laid out you could do this also: $filename = 'example.csv'; if ($hdl = fopen($filename, 'r')) while(list($a,$b,$c,$d, $e) = fgetcsv($hdl,1000)) echo "$a $d $e<br>"; // simple output of a single line else echo "Could not open file: $filename"; exit(); Note - I only use lowercase names. Makes it less prone to typos down the road. 2nd note - the echo line shows how to only print certain fields from your csv lines. And it does a very simple output. Instead you could begin an html table prior to beginning the while and then insert table rows for each line your read. Then close the table after the while ends. The key to all this is knowing your csv layout and providing fieldnames for each item in a row and then only referencing the ones you want to use. The list() construct works very nicely for this kind of thing.
  13. Instead of doing your final output as above where you simply dump the entire contents that you read in, why not simply print only the array elements that you want? As barand showed you your read process could only save specific elements of the csv lines you are reading. You could simply do the output right there instead of saving an array and then processing the data a second time.
  14. I tell FPDF that it is a letter and I space my text down a few lines and center it across the page. Then when I send the pdf to print I reset the paper to an envelope. Works great except for being backwards, ie, the envelope needs to be rotated away from the normal position in a the paper tray. I did try saving the pdf and then using Adobe to print it but for some reason it doesn't hold the same font size and prints at about 8pt size. No idea.
  15. With FPDF the page that the final pdf appears on (before printing) has a rotate option but it doesn't change how the printer prints in any way. Weird. I've added a JS alert to my submit button so that when I click on 'Make PDF' I remind the user (me) to rotate the envelopes. At least I won't waste them.
  16. I print envelopes all the time for other reasons and my printer has 2 trays with one of them setup and dedicated to envelopes. Having to remember to rotate them for one app's usage is a pia as you might imagine. I"m hoping that someone has seen this problem before.
  17. So - where is the code you are using?
  18. Have used FPDF many times for normal letter-sized printing but I am now having an issue with a #10 Envelope. While the printer tells you to insert envelopes a certain way and that's what I have done, for some reason FPDF won't print them the way the envelope is oriented but rather prints them upside down. To solve this I would have to remember to turn my envelopes around every time I used this application and I'm trying to avoid that. Has anyone figured out a work-around for this problem?
  19. Thank you for giving me credit for your solution but MacGyver actually mentioned it before me as I said earlier. HTH though!
  20. Ok - then that was what was pointed out earlier. Good luck.
  21. Ok - index.php is a good thing. So now show us more of your code. Hard to debug something when we aren't seeing it all Unless it is hundreds of lines in which case you have some work to do. Try adding my echo line to the very beginning of any php code in that file and be sure to move the 2 error checking lines up to the start of the php code as well.
  22. When you say 'index file' what do you mean? Are you saying that you are not using any script and letting your system just use the default home page name? What shows in the address bar when you do run it? Does it have a .php extension on it or is it an html extension? When you type in the ?con=xxx what is immediately in front of that? Show us that whole address bar line.
  23. What do you type in the browser's address bar to run this thing? That has the script name. The name of the program you are working on. That is the script name.
  24. Did you make the correction I posted? If you have fixed my code and tried to run it and got back no message and no error message give me the answers to my previous questions about the script name and the opening php tag.
×
×
  • 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.