Search found 140 matches

by simonbrahan
Tue Aug 24, 2021 1:48 am
Forum: PHP coding => General
Topic: How to break down this piece of short php?
Replies: 4
Views: 263

Re: How to break down this piece of short php?

You're not just calling stripslash; you're also calling do_shortcode. That's what's creating your form.
by simonbrahan
Tue Aug 17, 2021 1:05 am
Forum: PHP coding => General
Topic: Logic in MySql with PHP needed
Replies: 4
Views: 269

Re: Logic in MySql with PHP needed

MySQL could probably do what you're asking, but heavy logic isn't its strong point. You'd be better off porting your logic to PHP and just using MySQL for storing information.
by simonbrahan
Mon Aug 09, 2021 4:24 am
Forum: PHP coding => General
Topic: php
Replies: 2
Views: 288

Re: Pls halp! Is my short script ready 4 production?

From a security point of view, you're allowing users to write directly to a script file that your server will then run; htmlentities will protect you to a point but it's not great. The approach is unlikely to grow very well with your site; there's no way of giving more fine grained control to the re...
by simonbrahan
Thu Jul 22, 2021 12:59 am
Forum: PHP coding => General
Topic: I don't see the error with this array
Replies: 1
Views: 338

Re: I don't see the error with this array

Debugging 101! You need to look at what your code is dealing with on each line. You can do this with echo, print_r, var_dump, any outputting function. $handle = fopen("/etc/rpt.fifo", "r") or die("Unable to open file!"); var_dump($handle); // should give you something like "resource(2) of type (stre...
by simonbrahan
Tue Jul 20, 2021 9:36 am
Forum: PHP coding => General
Topic: Prevent Duplicate entry on form update with PDO
Replies: 6
Views: 712

Re: Prevent Duplicate entry on form update with PDO

Search for "mysql check for existence" and pick your favourite. Regarding code review, I'm sure someone will help you if you show your code.
by simonbrahan
Mon Jul 19, 2021 11:35 pm
Forum: PHP coding => General
Topic: Prevent Duplicate entry on form update with PDO
Replies: 6
Views: 712

Re: Prevent Duplicate entry on form update with PDO

You need two "sections" to your WHERE clause: a part that excludes the id you're looking at, and another part that checks for matching values. You can do this with brackets, the same way you do in maths: SELECT * FROM classes WHERE (class_name = :class_name OR class_number = :class_number) AND class...
by simonbrahan
Wed Jul 14, 2021 11:27 pm
Forum: PHP Scripts
Topic: How to iterate over an array according to a given condition?
Replies: 2
Views: 542

Re: How to iterate over an array according to a given condition?

You can loop over your data and store each item in a keyed array, like so: $grouped = []; foreach ($data as $item) { if (!isset($grouped[$item['equipment_id']])) { $grouped[$item['equipment_id']] = []; } $grouped[$item['equipment_id']][] = $item; } For the input you gave, this will give you: { "1414...
by simonbrahan
Sun Jul 11, 2021 11:38 pm
Forum: Server security
Topic: Disable dangerous php functions in php.ini to reduce security exploits
Replies: 5
Views: 788

Re: Disable dangerous php functions in php.ini to reduce security exploits

This is a decent list . Disabling them outright is likely to cause problems though; it wouldn't surprise me if the PHP applications you're running rely on a few of those functions. Rather than blindly disabling stuff, you should take the time to understand what code you're running and where the ris...
by simonbrahan
Wed Jun 30, 2021 12:31 pm
Forum: JavaScript
Topic: Any way to compress a cached file?
Replies: 1
Views: 415

Re: Any way to compress a cached file?

This library would downscale the video; This library would zip it. There are probably more. They may not help though; compresssing a video file is a slow process, and there's no guarantee that compression plus upload time will be quicker than just uploading.
by simonbrahan
Mon Jun 28, 2021 9:12 am
Forum: PHP coding => General
Topic: PHP 5 Internal error about chr(255).chr(254).@mb_convert_encoding
Replies: 3
Views: 680

Re: PHP 5 Internal error about chr(255).chr(254).@mb_convert_encoding

PHP should have logged the actual error to a log file; if you're running your PHP through apache it's likely to be in /var/log/apache/error.log. Without the error it's difficult to help you.
by simonbrahan
Wed Jun 23, 2021 11:07 pm
Forum: PHP coding => General
Topic: Can someone tell me what the 3 stands for in this URL?
Replies: 3
Views: 704

Re: Can someone tell me what the 3 stands for in this URL?

Both error_log and file_put_contents accept a string to put in the file; json_encode($userdata) will work fine. If it didn't work for you once, I'd guess there was an error elsewhere.
by simonbrahan
Tue Jun 22, 2021 1:12 am
Forum: PHP coding => General
Topic: Can someone tell me what the 3 stands for in this URL?
Replies: 3
Views: 704

Re: Can someone tell me what the 3 stands for in this URL?

From the documentation message is appended to the file destination. A newline is not automatically added to the end of the message string. If you want to completely overwrite any existing file with just this log entry, "error_log()" isn't the tool you need. file_put_contents will do it: file_put_co...
by simonbrahan
Mon Jun 14, 2021 10:38 pm
Forum: PHP coding => General
Topic: Question About Passwords
Replies: 2
Views: 646

Re: Question About Passwords

Look up "basic authentication"; this auth setup uses your web server only and allows you to set a password to access a folder. It can be done in apache using changes to a .htaccess file, and other server software will have their own way of doing it too. You can do something similar in PHP by storing...
by simonbrahan
Mon Jun 07, 2021 12:45 pm
Forum: Server installation and configuration
Topic: cPanel host, re-reading ini files
Replies: 3
Views: 975

Re: cPanel host, re-reading ini files

Depending on the option, you may be able to set it at runtime with ini_set.
by simonbrahan
Mon Jun 07, 2021 6:37 am
Forum: Server installation and configuration
Topic: cPanel host, re-reading ini files
Replies: 3
Views: 975

Re: cPanel host, re-reading ini files

You need to restart the web server for php.ini file changes to take effect. Normally:

sudo service apache2 reload

or:

sudo apache2ctl graceful
by simonbrahan
Sun Jun 06, 2021 11:37 pm
Forum: PHP coding => General
Topic: PHP Version 5.6.40, internal error for connect mysql
Replies: 5
Views: 898

Re: PHP Version 5.6.40, internal error for connect mysql

OK. That's odd. Can you remove the try ... catch wrapper and try it again? $servername = "localhost"; $username = "user"; $password = "password"; $db_database = 'db'; $db_port = '3306'; // Create connection $conn = mysqli_connect($servername, $username, $password,$db_database,$db_port); // Check con...
by simonbrahan
Sun Jun 06, 2021 12:31 pm
Forum: PHP coding => General
Topic: PHP Version 5.6.40, internal error for connect mysql
Replies: 5
Views: 898

Re: PHP Version 5.6.40, internal error for connect mysql

That error means you're trying to call a function - "mysqli_report" that doesn't exist. It's not written uin the code you've provided though, are you sure you've given us the correct script?
by simonbrahan
Sun Jun 06, 2021 5:11 am
Forum: PHP coding => General
Topic: NESTED ARRAY HELP
Replies: 2
Views: 623

Re: NESTED ARRAY HELP

The table doesn't have any information about what child item should appear under what parent. That's the first thing you need. Something like: id | parent | title 1 | null | Menu 1 2 | null | Menu 2 3 | 2 | Menu 2.1 4 | 2 | Menu 2.2 5 | null | Menu 3 6 | 5 | Menu 3.1 7 | 6 | Menu 3.1.1 8 | 5 | Menu ...
by simonbrahan
Sun Jun 06, 2021 5:09 am
Forum: PHP coding => General
Topic: PHP Version 5.6.40, internal error for connect mysql
Replies: 5
Views: 898

Re: PHP Version 5.6.40, internal error for connect mysql

Turn errors on so you can see what the problem is.

You should probably set mysqli to throw exceptions as well; that will stop you having to muck around with error handling code.

Code: Select all

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
by simonbrahan
Sun Jun 06, 2021 4:49 am
Forum: PHP coding => General
Topic: change color of readline_callback_handler_install
Replies: 1
Views: 547

Re: change color of readline_callback_handler_install

There's no way to do it directly. You could spoof it by echoing your prompt manually then having a blank "prompt" in your readline handler. The example below shows how it works with readline().

Code: Select all

echo "\e[0m\e[34m Wacky coloured prompt: \e[0m";
$foo = readline('');
by simonbrahan
Sun Jun 06, 2021 4:29 am
Forum: PHP coding => General
Topic: My html php page does not display utf-8 characters
Replies: 1
Views: 522

Re: My html php page does not display utf-8 characters

It may be that your web page is not being served as UTF8. Try adding this line immediately after your opening <HEAD> tag:

Code: Select all

<head>
<meta charset="utf-8"/><!-- add this line -->
by simonbrahan
Tue Jun 01, 2021 12:13 am
Forum: PHP coding => General
Topic: Remove an out of spec item from an array
Replies: 2
Views: 623

Re: Remove an out of spec item from an array

You'd need to write something to do it. PHP doesn't know what your data represents, so can't know what a spurious result is.
by simonbrahan
Sun May 30, 2021 6:18 am
Forum: PHP General
Topic: reinstall old cakePHP v1.3.11 project
Replies: 5
Views: 877

Re: reinstall old cakePHP v1.3.11 project

It looks like the code is running in the file /var/www/html/NlLaosF/app/app_controller.php

The relative path being checked for is ../../app/webroot/lang/lang_en.php

That is parsed to /var/www/html/app/webroot/lang/lang_en.php - that's what's gone wrong.
by simonbrahan
Sun May 30, 2021 3:22 am
Forum: PHP General
Topic: reinstall old cakePHP v1.3.11 project
Replies: 5
Views: 877

Re: reinstall old cakePHP v1.3.11 project

The fatal error says a file is missing. Is the file it's talking about where it should be?
by simonbrahan
Sat May 29, 2021 10:45 am
Forum: PHP General
Topic: reinstall old cakePHP v1.3.11 project
Replies: 5
Views: 877

Re: reinstall old cakePHP v1.3.11 project

Paste the errors as text, the image is illegible.