|
Is there a way to connect to postgres server from php using ssl client certificate authentication instead of password?
|
# ? Dec 16, 2016 07:54 |
|
|
# ? May 31, 2024 18:55 |
|
Negative string offsets in 7.1 seem fun and convenient https://3v4l.org/8sndO
|
# ? Dec 16, 2016 16:22 |
|
Forgall posted:Is there a way to connect to postgres server from php using ssl client certificate authentication instead of password? Copying and pasting your question into Google indicates yes, there is.
|
# ? Dec 20, 2016 20:10 |
|
rt4 posted:Negative string offsets in 7.1 seem fun and convenient is that only for strings or is it for any array?
|
# ? Dec 21, 2016 04:16 |
|
The Wizard of Poz posted:is that only for strings or is it for any array? Negative offsets in strings using the array syntax is one of the new 7.1 features. Negative offsets continue to not work in arrays, as it's actually possible to have negative numbers be actual legal, existing keys in PHP arrays.
|
# ? Dec 21, 2016 09:29 |
|
I'm having some trouble with the logic and coding of this. Any help is appreciated. I have an array of date intervals. I need to create another array of continous intervals. Sorry, I'll try to explain. code:
I need to put the startDate from element 0 in it's own array with the stopDate that doesn't match with the upcoming startDate. The output generated would be: code:
|
# ? Dec 22, 2016 21:34 |
|
Try using array_reduce:PHP code:
|
# ? Dec 22, 2016 22:25 |
|
If there's a chance that a subsequent startDate may be slightly before the preceding stopDate, it might be worth looking at a library that can properly handle ranges—I used https://github.com/judev/php-intervaltree on an older project to reduce overlapping segments to a single segment.
|
# ? Dec 22, 2016 23:33 |
|
PHP newbie here. I'm trying to make a form that submits data to a database. I have the database set up fine, got it connected and disconnected properly. And I can even get the data submitting. The only problem is I'm trying to create functions to make the process easier and I'm having issues. My index page: code:
code:
Also, I know extract with $_POST is bad practice, but I'm just practicing.
|
# ? Dec 29, 2016 22:19 |
The basic thing is that you are calling add_word() incorrectly, you pass a stringified version of $_POST which is useless, instead of just passing it directly. This is wrong: code:
code:
code:
You should also use parameterized queries instead of munging values and pasting them into SQL strings directly.
|
|
# ? Dec 29, 2016 22:29 |
|
Okay. I tried fixing that stuff:code:
code:
|
# ? Dec 29, 2016 22:40 |
Oh right, $connection in that mysqli_query call, that's probably a global. If it is you need to declare it as such at the start of the function body. http://php.net/manual/en/language.variables.scope.phpv
|
|
# ? Dec 29, 2016 22:50 |
|
Okay. It's working and I got the clean function going as well. PHP is weird, man. I miss JQuery right now Also, will that clean function protect me from every SQL injection? Is there better ways of doing it or is real escape string efficient enough? teen phone cutie fucked around with this message at 23:11 on Dec 29, 2016 |
# ? Dec 29, 2016 23:09 |
|
Grump posted:Okay. It's working and I got the clean function going as well. This seems like a decent enough tutorial: http://www.phptherightway.com/#databases Forgall fucked around with this message at 23:26 on Dec 29, 2016 |
# ? Dec 29, 2016 23:22 |
|
mysqli is not and will not be deprecated. However, you should still consider using PDO while learning PHP, as using prepared statements with mysqli is unnecessarily annoying compared to the way PDO does it. Unless you have no other plausible choice, never ever ever assemble SQL as a string using user-provided data. Always and only use prepared statements. There are times to break this rule due to restrictions on what you can do with prepared statement placeholders, but treat it as religious dogma until you begin doing advanced / weird stuff. As a learner, something to keep an eye out for is the date on any tutorials you come across. Trust nothing made more than five years ago, and trust nothing designed for PHP versions prior to 5.3. If there is no date on the tutorial, assume it's trash and move on.
|
# ? Dec 30, 2016 04:49 |
|
IMHO stick composer in your app, add its autoloads, and then use eloquent to do your DB stuff. It uses PDO on the back end, and you can use it to just run plain queries, but it gives you a lot more power. Plus, you'll have composer which you can use to pull in other libs with ease.
revmoo fucked around with this message at 17:53 on Jan 26, 2017 |
# ? Jan 26, 2017 17:51 |
|
Dumb PHP question: What the hell do people write PHP in? I'm setting up a phpBB forum my company which I need to make modifications to. I haven't used PHP in over 5 years when I was in college. And even then it was just for some stuff we'd write entirely ourselves so Notepad++ was fine. But jumping into an unfamiliar codebase with 1500 files in a language I haven't used in too long is a bit overwhelming. After half a decade of using .NET I am a soft and delicate flower who misses things like "Go To Definition" to find where a variable is declared or a class/method implemented. Or "Find All References" to see every where in the codebase something is called. Edit: I'm on Win7 if that matters.
|
# ? Feb 3, 2017 14:46 |
|
PhpStorm isn't free, but they got a trial. Can check it out.
|
# ? Feb 3, 2017 14:59 |
|
PhpStorm is definitely the best, but NetBeans is the second best PHP IDE if you don't want to spend any money.
|
# ? Feb 3, 2017 15:20 |
|
Yea I doubt the bossman would buy the license given this is a lower priority project. I used NetBeans for Java in college and hated it seemed so slow. Hopefully newer versions are better. And goddamn I just realised that in N++ if I double click a variable name it doesn't grab the $ with it, so then the syntax highlighting highlights strings that match my selection and stuff
|
# ? Feb 3, 2017 15:44 |
|
I've never worked for a company will pay for an IDE so I just pay for it myself. Personal license are cheaper than commercial ones. Jetbrains licenses their IDEs for use on every machine you work with, so I use a single license both at home and at work.
|
# ? Feb 3, 2017 16:05 |
|
Yeah in this case I'd advise paying for PHPStorm yourself. I personally use Vim but if you're just getting re-acquainted PHPStorm will do some nice hand-holding.
|
# ? Feb 3, 2017 17:51 |
|
Notepad++ works well for PHP too, and it's free!
|
# ? Feb 8, 2017 00:46 |
Is there a function or sample code that can exactly reproduce javascript's deprecated escape() function? I know it's deprecated, but our partner won't update their code so we need to replicate it in PHP. I've tried googling but every response is just people saying "don't use deprecated code" and unfortunately we don't have that luxury.
|
|
# ? Feb 10, 2017 11:04 |
Sulla-Marius 88 posted:Is there a function or sample code that can exactly reproduce javascript's deprecated escape() function? I know it's deprecated, but our partner won't update their code so we need to replicate it in PHP. I've tried googling but every response is just people saying "don't use deprecated code" and unfortunately we don't have that luxury. Untested: PHP code:
This "should" handle Unicode within the BMP, and fails with characters outside the BMP. E: The best way to support non-BMP characters may be to first convert the input string to UTF-16 and then process that. It may even be shorter code. nielsm fucked around with this message at 12:36 on Feb 10, 2017 |
|
# ? Feb 10, 2017 12:33 |
You are amazing!! I tried recreating it myself earlier on using the RFC, but I was absolutely not capable of it. A minor modification on the sprintf() and a missing semi-colon and it's reproducing exactly what I need: php:<? function js_escape($str) { $fn = function($matches) { $string = $matches[0]; $offset = 0; $code = ord(substr($string, $offset, 1)); if ($code >= 128) { if ($code < 224) $bytesnumber = 2; else if ($code < 240) $bytesnumber = 3; else if ($code < 248) $bytesnumber = 4; $codetemp = $code - 192 - ($bytesnumber > 2 ? 32 : 0) - ($bytesnumber > 3 ? 16 : 0); for ($i = 2; $i <= $bytesnumber; $i++) { $offset++; $code2 = ord(substr($string, $offset, 1)) - 128; $codetemp = $codetemp*64 + $code2; } $code = $codetemp; } if ($code < 256) { return sprintf("%%%'02X", $code); } else { return sprintf("%%u%'04X", $code); } }; return preg_replace_callback("|[^ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789@*_+-./]|u", $fn, $str); } ?> Sulla Faex fucked around with this message at 16:45 on Feb 10, 2017 |
|
# ? Feb 10, 2017 16:32 |
|
Having issues getting XDebug working. - Windows 7 - IIS 7.5 - PHP 5.6 - phpBB3 is the application I'm trying to setup I've downloaded and installed Netbeans. I pasted phpinfo(); output into XDebug's wizard. I downloaded the file the wizard linked, moved that C:\php\ext. I've added zend_extension = .\ext\dllFileName I restarted IIS. Load up Netbeans, open my project, adjust the "Project URL" settings and click Debug Project. This opens my browser to http://localhost/phpBB3/?xdebug_session_start=netbeans-xdebug But none of my breakpoints fire. Did I do something wrong?
|
# ? Feb 13, 2017 17:12 |
|
nielsm posted:Also, you should never, ever use the extract() function. old post but, extract() has its uses. The example that comes to mind is before require()-ing a template.php inside a render() function
|
# ? Feb 14, 2017 07:12 |
|
Luxury Communism posted:old post but, yeah I ended up fixing that. I was just watching Lynda tutorials at work bc I was bored and was trying to make a simple CRUD. The only time I ever worked in PHP was while I was still in school, and never really got the chance to wrap my brain around it. I'm wondering if it's even worth learning or if it's more valuable to learn Node js as a server-side language, as I'm mainly working with Javascript at work.
|
# ? Feb 14, 2017 23:50 |
|
PHP has a huge, but mostly lovely base of installed software. PHP tends to pay less than other languages from what I can tell. Node had a sharp rise, but quickly hit a plateau in adoption. If I was going to start learning a server-side language, I'd learn Python or Java. Python has lower barriers to entry.
|
# ? Feb 15, 2017 01:10 |
|
Grump posted:I'm wondering if it's even worth learning or if it's more valuable to learn Node js as a server-side language, as I'm mainly working with Javascript at work. Doing server-side javascript requires not just learning how to deal with async bullshit in node.js, it also requires that you learn multiple mandatory tools. JS has an incredibly tiny standard library and the culture and tooling that's sprung up to try and deal with this problem are broken and probably unfixable. PHP might be a poo poo language, but you aren't inexorably, permanently linked to broken tooling just by using it. If you want to learn a better language than PHP, I'll echo the suggestion to learn python.
|
# ? Feb 15, 2017 03:01 |
|
gently caress it, learn Clojure
|
# ? Feb 15, 2017 03:21 |
|
Another dumb question (don't worry; I'm almost done with this project and then I can stop shitposting in here) So I spent more time than I'd care to admit today tracking down a bug. Turns out I accidentally omitted a $ before a variable name. My question is, why the gently caress didn't this blow up? php:<? for ($i = 0; i < count($someArray); $i++) { foo($someArray[i]); } ?> Does that mean that i must've represented something? If not, why didn't this throw some sort of error?
|
# ? Feb 15, 2017 05:08 |
|
bare identifiers like 'i' are considered as references to constants, and by dubious tradition, if that constant's name wasn't already defined, it evaluates to itself (in this case, the string "i"). comparing a string with a number in that way generally causes the string to be parsed as a number, which always leads to good times (in this case, "i" is parsed as zero every time the loop iterates and the loop doesn't halt). this evaluation-of-undefined-constant raises a notice-level error, but with common default php settings this notice doesn't interrupt execution, it just prints a message to stderr or wherever errors have been redirected by your server setup. so it's important to be able to figure out where to see the error output when running a script -- this would have been printing notices somewhere for those 10 minutes. this is also one reason many people like to configure php to use ErrorExceptions, like this example because it will make php be strict about those kinds of errors and cause an immediate termination of the script. unfortunately php isn't as easy to deal with in windows; a lot of its history is tied closely to unix and related libraries. while it's easier to mix the two now, it's still greatly colored by its history with unix/linux and its relationship with server programs like apache. if it's an unexpected nuisance of a project, you just do the best you can do with php, i guess. but if you are going to spend more than a few weeks with it, it'll quickly start to pay off if you spend time getting familiar with the characteristics it inherited from linux & apache. hope that doesn't apply to you though!
|
# ? Feb 15, 2017 05:55 |
|
An IDE that puts a red underline under things like that is worth its weight in gold
|
# ? Feb 15, 2017 14:38 |
|
There are some frameworks that registers a handler for notices and convert them to either errors or exceptions. You can do this your self too with:PHP code:
I find it pretty useful to do so as most php notices should be errors imo.
|
# ? Feb 15, 2017 15:26 |
|
EDIT: Post about a delete function. I ended up making unique pages for each row in my table and then adding a delete button on each page. I originally wanted to list them all and have a delete button next to each item in the list, but I decided that was over my head, so I did it this way instead. Hey! I'm getting better at PHP CRUD! PHP code:
teen phone cutie fucked around with this message at 20:42 on Feb 15, 2017 |
# ? Feb 15, 2017 16:28 |
|
The most important thing about that code sample is that it takes user in put from $_GET['id'] and sticks it directly into a query. You need to use a parameterized query to prevent a malicious user from carrying out an SQL injection attack. http://php.net/manual/en/pdo.prepare.php
|
# ? Feb 15, 2017 20:49 |
|
This is a dumb question, but I have a wordpress plugin that has since updated and says that it no longer supports PHP 5.2 and under. I checked my phpinfo and it says 5.4.45, which theoretically checks out. However the impression I get is "if not compatible with 5.2 then it's 7.0 only"; am I safe to upgrade this plugin, or do I have to upgrade to PHP 7?
|
# ? Feb 15, 2017 21:47 |
|
|
# ? May 31, 2024 18:55 |
|
rt4 posted:An IDE that puts a red underline under things like that is worth its weight in gold I started using Netbeans instead of N++. I don't think it was underlined in yellow, but maybe it was. loving impossible to notice yellow underlining on a white background through. I suppose there would've been a notification flag in the line-number section... But yea; pretty sure there was no "heads up"
|
# ? Feb 15, 2017 23:06 |