Jump to content

mogosselin

Members
  • Posts

    116
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by mogosselin

  1. If it works perfectly, where is the problem then? What do you have trouble with? You don't know where to start? With just one line of code you can append a line in a file. Checkout: http://php.net/manual/en/function.file-put-contents.php You need to use the FILE_APPEND flag. Like: file_put_contents ("file.dat" , $linetoadd , FILE_APPEND);
  2. What do you mean by 'CRUD' with OOP? Do you mean using PDO? Or you mean learning how to do a CRUD on a DB AND learning OOP at the same time? If it's the last, you should probably break up the learning process. Search for PHP and OOP on Google. Then, search for PDO insert, PDO update, PDO select, etc. If it's the first, simply search for PDO insert, PDO update, etc. I have some tutorials on my site about PDO (simple insert), but not on every CRUD parts.
  3. Are you talking about a Filezilla server or client? Also, the find command returns multiple results, not sure how it would work with a command to open it. It would probably just open the last or the first one? (I'm not a Linux expert). And do you have a graphic interface where you can see the 'stars' where the password should be? If yes, maybe there's a tool that would 'unstar' the password.
  4. What do you use to edit your PHP file? Check the the files the editor creates are encoded in UTF-8. Is UTF-8 your default charset with PHP? Check with phpinfo(); the value default_charset Do you use header('Content-Type: text/html; charset=utf-8'); ? Do you use any string functions on the data before echoing it?
  5. Are you sure $prices and $prices[$i] are arrays? Check with is_array(). This 'illegal string offset' error often happens when someone tries to access a string as if it was an array. You could try something like: if (!is_array($prices)) trigger_error('$prices is NOT an array!', E_USER_ERROR); if (!is_array($prices[$i])) trigger_error('$prices[$i] is NOT an array!', E_USER_ERROR); ... your code here ... You should never 'silence' errors. This is done only by lazy programmers that doesn't care about doing their job correctly. A good programmer should find where the error comes from, understand it and make it disappear by using proper code (except in sore rare occurrences where it's OK to silence an error: a bug that you can't correct from PHP or an external library, which is uncommon).
  6. Tip: you can use the <> icon in the tool bar to post your code, so that it will have syntax highlight and will be easier to read. The first step for you would be to try to achieve the result in pure / hardcoded HTML first. Try to do this, then try to apply it to your PHP code.
  7. It's hard to help you without 'real' data or at least, really knowing what you want to do. So far, I understand that: You have 2 different databases You have 1 table about a user in DB1? And a second table about all the users in DB2? Than, something gives you an array in an array in an array... The parts that are missing to help you: What's the structure of the tables in DB1 and DB2 that you're trying to query? What is the information you're trying to get from the DB? What's the actual code that produce this array you posted in the first message? And what's the format in which you're trying to display the data? (show an example of a desired result)? Or what are you trying to do with the data in the arrays? What's your 'process' you're talking about? If you can answer those questions, it'll be way easier to help you
  8. Like @requinix said, you can check if the line you added in the .htaccess is present in the HTTP header when you call the files. To do that, use the tab 'Network' in Google Chromes' Developer tools (or other developer tools on other browsers). The HTTP header is something that you don't 'see' when you look at a web page, but it is always present when you ask for a web page.
  9. Another way to put it... When the user clicks on a link (or a button) to see their message, you're going to issue a request to output this message. Something like: SELECT * from Message WHERE id=3 ... or whatever. Then, right after you did this request, do another one that will update this row: UPDATE message SET read=true WHERE id=3 There's also something called a 'Trigger' in MySQL... so you could do it directly on the database and you wouldn't need any code, but this doesn't work with a SELECT (insert, delete and update only). So, there's no way to know if a row has been read except to update something right after you've read it.
  10. Hi! There's a 'code' button in the toolbar where you wrote your post. You can edit your post and paste your code in the little box that will appear. Your code will be much more easier to read. Now, it's kinda hard to see, and I'm not talking about that green font there
  11. It seems to me like you're fairly new to PHP and you're trying to do something with Joomla? If you don't understand the error messages and you're 'playing' with Joomla, it's normal that you're lost... Also, if you copy a piece of code and put it there in the hope that it'll work (without understanding how it works), well... the changes are that it won't work All the code that you copied from the timezone thing isn't necessary. You just need something like: date_default_timezone_set('America/Los_Angeles'); You should choose the timezone of your PHP server from the list here: http://php.net/manual/en/timezones.php Don't just write 'Los_Angeles' if your server isn't in the same timezone, you'll end up with weird results. All the rest of the code in the example is just meant to check if the timezone you set in your code is the same as in your INI settings. When I say "ini settings", it means your PHP configurations. Do you know where your php.ini file is and what it contains? For the other error message, it's similar to the popular 'Headers already sent' error. The 'Header' is something that your server will send to the browser requesting the page. But, the header needs to be first, before any content is sent. And, the header contains cookies (and cookies are used to manage sessions). So, if you send content to the browser (like with a echo "hello", or a blank space, etc.), and then you try to add a cookie, it won't work. The header was already sent... If you want a detailed explanation on how this work, I already wrote a post about it (it's not the exact same error, but it's similar). That being said, why are you using Joomla? Can't you just start with plain PHP and do a simple 'contact form' or any other simple application? It would be, IMO, a better way to start with PHP.
  12. Also, depending on the number of users you want to send emails to, you should check the possibility to use an external newsletter service. You'll need to pay for it, but it will be more reliable. If you send a lot of email from a single web mail server, you could get 'banned' from gmail, yahoo, etc... And some of your emails could end up in the spam directory more easily than if you use a mailing service. Just my 2 cents
  13. For the Google API, I think that for the free version you need to display Google Map on your page to query their API with that kind of request. But, you can also get it with HTML5: http://diveintohtml5.info/geolocation.html Which will probably require some Ajax on your part because it's on the client side. And, the user will need to approve the geolocation request (depending on his settings).
  14. If I would translate the error message to 'human error message': You tried to call the method 'GET' on a variable... Normally, when you call a method with ->, it's for an object. But you tried to call it on a variable that is not an object. It's hard to tell because your code isn't complete, but it probably comes from this line: $check = $this->_dddd->get(.......) It's the only place where you have a 'get'... My guess would be that _dddd is still null. And since 'null' is not an object and you try to call GET like if it was, that's probably why you get that error.
  15. The error you get has to do with this code: $stmt = $handler->prepare('INSERT INTO calendar_event (title,short_desc,full_desc,date) VALUES (:title, :short_desc, :full_desc, :date)') ; $stmt->execute(array( ':title' => $title, ':short_desc' => $short_desc, ':ful_desc' => $full_desc, ':date' => date('Y-m-d') )); More specifically, the 'placeholders' like :title, :short_desc, etc... When you try to bind the parameters of your query with actual values, PDO/PHP will throw an error at you if you don't have the right amount of 'parameters' to replace the placeholders. For example, if you have a query like: 'SELECT * FROM user WHERE username = :username and title = :title' and you try to bind the parameters like this: $stmt->execute(array( ':title' => $title )) PHP won't be happy, because the :username is not there. It will then throw you this error: Invalid parameter number: number of bound variables does not match number of tokens Same thing if you make a mistake while typing your placehodlers VS the name that you pass in the array. If for the same request I would do: $stmt->execute(array( ':title' => $title, ':usernameWithATypo' => $username )) Notice how ':usernameWithATypo' is not the same as the ':username' we had in our query.... If you do this, PHP won't be happy and will throw you a similar error message: Invalid parameter number: parameter was not defined in We could argue that the 'Invalid parameter number' isn't technically OK, because we sent the right amount of parameters expected, only one that wasn't correctly spelled... but still, that's the error that PHP will throw. As for catching the errors that PDO sends, it's true that it's not a good practice. What you want to do in your 'live' website, is to display a nice error page to your users. To do this, you can use the method 'set_exception_handler' - Also, here's a post I wrote about it if you're interested to know more. So, in summary, you probably don't need the 'try catch' for PDO exception and you can just let them 'bubble up'. And, if you specify a function with set_exception_handler', this function will be called each time an exception is raised and not catch. Which makes it way easier
  16. I think that's what Ch0cu3r suggested... You'll have to generate an image 30 times and include those 30 images in an HTML pages. I don't know why you talked about 'frames' in your first post, but using frame here doesn't make sense (if you talk about HTML frames or iframes). Here's what you'll need to do (that's pseudo-code, meaning that it doesn't really work, it's just to show you the logic): // Generates an image with the $data passed as the first parameter // returns the image path that we created function generateGraph($data) // generate an image with the $data // return the path of the image return $imagePath // Loop trough all image data // Create images one by one // Display the image for ($i: 0 to $numberOfImages) $imagePath = generateGraph($dataImage[$i]); echo <img src="$imagePath"> I hope it helps!
  17. What you want to do when you develop (meaning on your computer or a test server or whatever) is to display ALL of the messages PHP can send to you so that you can fix them as soon as possible. When your code is 'live' (accessible from the Internet), you want to display a nice custom error page. You certainly don't want to show to your users error messages coming from PHP. It's not secure, it's ugly and it won't help your users anyway. But, you want to be able to see the errors, that's why you should at least log them. To try what's happening on your server (either it's on your production or development server), you can create a single PHP file with only this content: <?php foo(); The function 'foo()' shouldn't exist, so when you call that page, you should see an error message. If you see a white page, it's because your PHP error settings tells PHP not to output any error. If you actually want to see the errors, you could change your settings in php.ini to: display_errors=On error_reporting=E_ALL log_errors=1 Or, if you want to (but it's not the cleanest way), you can add this to your code: If you want to know more, I wrote an article about Error settings with PHP. If you read it, I'd love to have your comments!
  18. You could set your $applicant into the session using $_SESSION['applicant'] = $applicant. And then, to retrieve it in your other script: $applicant = $_SESSION['applicant']; Note that you need to use session_start() before using the $_SESSION variable. session_start() info: http://php.net/manual/en/function.session-start.php $_SESSION info: http://php.net/manual/en/reserved.variables.session.php Note that you can use the 'code' button when you write your post to include code. It will be easier to look at it that this way
  19. I don't exactly know your use case and what PFsense do. And, I'm not a Hardware expert, but I'm pretty sure that if you pass trough a modem of some sort to go on the Internet, you'll have this modem's MAC and IP address. So, 2 persons on 2 computers going through the same modem would get the same MAC address. It means that I could get the information of my colleague filled up. You should check if it's problematic for your use case. Also, if you want to check more than just yesterday's log, you could just load those information into a database once a day. Add a cron job at midnight to load the last log file into a DB.
  20. So, if I understand correctly, you store user information in a log file. One line equals one user? So you have a lot of data on the same line (mac address, ip, etc.) for each users. Then you need to open the file, parse the lines and find the user quickly to fill out its information. If it's what you're doing, this would normally be done with a Database. What's your key for your user? IP address? MAC address? Remember that the IP and MAC address could be the same for multiple users. For example, at my work, we all have the same IP and MAC address.
  21. Hello cobusbo! Did you write the script you posted or did you find it somewhere? What you should do is to create a couple of files in a directory and just create small, standalone PHP file. In this file, try to list all the name of the files in this directory. Then, try to do it by date. You should be able to do it with what Ch0cu3r said. Tell me if you're able to do that or not.
  22. The magic keyword here is rowspan. You need to set your row span on your 'title' cells for the number of rows they should take. Here's an example: <!DOCTYPE html> <html> <head> <title>Table merge</title> <style> table tr td { border:1px solid black; padding: 4px; } </style> </head> <body> <table> <tr> <td rowspan='2'>Row 1</td> <td>lorem ipsum</td> <td>lorem ipsum</td> <td>lorem ipsum</td> </tr> <tr> <td>lorem ipsum</td> <td>lorem ipsum</td> <td>lorem ipsum</td> </tr> <tr> <td rowspan='2'>Row 2</td> <td>lorem ipsum</td> <td>lorem ipsum</td> <td>lorem ipsum</td> </tr> <tr> <td>lorem ipsum</td> <td>lorem ipsum</td> <td>lorem ipsum</td> </tr> </table> </body> </html> So, you'll need to loop through your rows and count the number occurrences of the same title. For example, if your 'test prix 2' is displayed 5 times and you want to merge 5 cells vertically, you'll need to set your rowspan to 5 and NOT display all other 4 <td> tags with that title.
  23. Yes, you can read it line by line without busting the memory: But yes, it will take time (depending on how big your file is). More info on fgets in the official PHP guide Depending on what are the information in your files (like mac_gyver said), it would probably be a good idea to use a database. You could create a script that reads your text file and put them in the database each hour or day etc. depending on what you need. That's a usual 'load' process. If you need something more robust, think about using a queue system (RabitMQ for example) to load your files in a database. Or, depending on what you need your data for, you could also load it in a search system (Solr, Elastic Search) so that you can issue super fast search queries. If you want more precise tips, tell us what you're using your data for and what's the average volume (number of lines, etc) and if there are relations between those files.
  24. Hi Lectrician! In the official PHP guide about the flock function, it says: To test it, simply add a sleep(30) after acquiring the lock and before releasing it. While it sleeps, open another tab and ask for the same page. The second time you request the page while the first one is sleeping, it should wait until the first page release the lock and continue.
  25. Hi Digitizer! I suggest you to post your code on GitHub and then ask for a review by simply adding a link. It'll be way easier than to upload files here or to paste code of 10 files in a post.
×
×
  • 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.