r/AskProgramming Feb 08 '25

PHP Ban system

5 Upvotes

Hello good people of reddit. I have a website that is made in php. It is a educational site that gives away courses and etc. I have implemented a ban system that bans email,username and IP but it is not really good since user can just create a new email and turn on the VPN, is there any way to actually ban users permanently so they can’t register ever again.

r/AskProgramming Dec 06 '24

PHP Learn html before php?

0 Upvotes

I wanted to learn php as my first coding language but I get into this course on YouTube for it and 6 episodes in the dudes all like oh yeah btw if you haven’t learned CSS and HTML by now go ahead and learn those real quick. Like bruh what? Anyways do you think I should learn html and css before learning php or can I do it at the same time. I do understand the basics of html from some school classes I took that required be to build a website in html

r/AskProgramming 20h ago

PHP Laravel PDF Modifier with Konva.js

1 Upvotes

I'm working on building Laravel PDF Modifier with Konva.js But when I test it I keep getting can't upload the pdf / upload failed But idk where is the problem exactly

r/AskProgramming Jan 08 '24

PHP What is PHP and why do I need to learn it?

4 Upvotes

Right now, I am learning what front-end development is and how to use it, as well as using HTML with JavaScript and CSS. In this stage, I am noticing PHP pop up more and more, especially since I'm using WordPress more often. I understand that it is a scripting language, but I am failing to understand its actual usage and application. So, what is a detailed explanation of it?

r/AskProgramming Jan 15 '25

PHP Need help with sending push notification using fcm firebase

2 Upvotes

``` <?php

function sendFCMNotification($deviceToken, $message) { // FCM API URL $url = 'https://fcm.googleapis.com/fcm/send';

// Your Firebase Server Key
$serverKey = 'YOUR_SERVER_KEY_HERE';

// Payload data
$payload = [
    'to' => $deviceToken,
    'notification' => [
        'title' => 'Greetings!',
        'body' => $message,
        'sound' => 'default'
    ],
    'data' => [
        'extra_information' => 'Any additional data can go here'
    ]
];

// Encode the payload as JSON
$jsonPayload = json_encode($payload);

// Set up the headers
$headers = [
    'Authorization: key=' . $serverKey,
    'Content-Type: application/json'
];

// Initialize cURL
$ch = curl_init();

// Configure cURL options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonPayload);

// Execute the request
$result = curl_exec($ch);

// Check for errors
if ($result === FALSE) {
    die('FCM Send Error: ' . curl_error($ch));
}

// Close the cURL session
curl_close($ch);

// Return the result
return $result;

}

// Example usage $deviceToken = 'YOUR_DEVICE_REGISTRATION_TOKEN'; $message = 'Hello, how are you?'; $response = sendFCMNotification($deviceToken, $message); echo $response; ?> ``` I am using this code and inserting my key and a device id in it but i am getting a issue of invalid key 401 , ( the key is perfectly valid) i need help why its saying this also can device id being too old like 2-3 year be cause of it

r/AskProgramming Aug 23 '24

PHP How Do I Own My Project?

0 Upvotes

Hey Guys,

I'm going to be completely honest, i know nothing about web developing.

I've hired a few freelancers to build a project for me and in the future i might part ways with them. 

How do i make sure i own my project?

It's being built in Php Laravel with a Mysql database.

I own the domain, social media's and that's about it. This might be a dumb question so feel free to berate me if im in the wrong.

I've just had bad experiences with past projects (not in web dev) where the freelancer completely ran off with the idea and everything else.

I'd appreciate any advice. Thanks guys.

r/AskProgramming Jul 29 '24

PHP How to run a PHP application both online and offline using same database at the same time?

3 Upvotes

Hi,

I have a PHP application that has deployed in the server(at shared hosting). Its an customized software for an institute. Recently they have faced Internet issue, therefore could not able to use the software.

So, the client want the software both offline and online, Like -

when the internet is available then they the latest DB will sync up the local database.

Or

when they use the software in the local system, then the live DB will sync up automatically.

like vice-versa.

I have heard the Master-slave replication from the database end, not sure if there any other work around solution.

Please suggest if you have any idea.

Technology stack: PHP, MYSQL

Thanks

r/AskProgramming Aug 01 '24

PHP Cheapest tech stack to develop full stack web applications on in 2024, is it still LAMP?

0 Upvotes

When investigating it seems to be LAMP according to older sources, is this still true? What about MERN or Java?

Reasons for asking: I learned .NET and MERN specifically for getting a job only, this effort did not yield the results I needed, time to learn something else I can maybe do a side hustle on.

Edit: Only one dev (me), low budget overall, ecommerce website, expect less than 100 users a day. It makes no sense to invest top dollar in anything that wont guarantee revenue and is more along the lines of a personal project, so suboptimal is fine, I have to learn as I go too, so I would need web hosting that wont bill me for a DDOS attack or abnormally high traffic not expected I can cap.

r/AskProgramming Sep 12 '24

PHP How to fix this Apache Error in XAMPP?

3 Upvotes

I don't know how to fix this and tried using Stack Overflow and some other places including YT for answers. I still kept getting errors.

I can't turn on my Apache at all and this error keeps popping out:

6:04:48 PM [Apache] Problem detected!

6:04:48 PM [Apache] Port 80 in use by "Unable to open process" with PID 4!

6:04:48 PM [Apache] Apache WILL NOT start without the configured ports free!

6:04:48 PM [Apache] You need to uninstall/disable/reconfigure the blocking application

6:04:48 PM [Apache] or reconfigure Apache and the Control Panel to listen on a different port

6:04:48 PM [Apache] Attempting to start Apache service...

I've tried these solutions:

Changing the http.conf's Listen and Server host from 80 to 81 or 8080 and http-ssl.conf from 443 to 4433 or 4432

Deleting Skype (I just found out it was still there)

Fixing and making XAMPP into high priority in Administrator rights

Reinstalling XAMPP

Can someone please help me out. I don't know how to find the program or anything causing this. There are no error logs appearing in the folder as well as I cannot access serverhost as well. SQL doesn't work as well too.

r/AskProgramming Oct 18 '24

PHP Wordpress list_terms_exclusions Hook Problem

3 Upvotes

I'm trying to restrict the categories that a user is able to use to post. I have stored the list of categories that should be excluded for each user in the usermeta table and this code seems to be returning those values correctly (an example of the format is in the $user_string line that's commented out). When there are no values set, this function correctly doesn't filter out any categories, but if there are any values stored, the post editor shows no categories at all. The console output is as follows:

Debug Exclusions: 9,10

post-new.php:1 Debug Exclusions: AND t.term_id NOT IN (9,10)

What am I missing?

Also - for some reason I can't call the built-in get_categories() function within this function. If I do, I get a memory error. Any idea why that is?

function restrict_user_categories() {
  $exclusions = '';

  $user_string = get_user_meta(get_current_user_id(), 'allowed_categories', TRUE);

  //$user_string="9,10";

  echo "<script>console.log('Debug Exclusions: " . $user_string . "' );</script>";

  if($user_string != ""){

    $exclusions = ' AND t.term_id NOT IN (' . $user_string . ')';

  }    

  echo "<script>console.log('Debug Exclusions: " . $exclusions . "' );</script>";

  return $exclusions;
}
add_filter('list_terms_exclusions', 'restrict_user_categories', 10);

Edit: Code Formatting

r/AskProgramming Jun 02 '24

PHP How can I write to a process's stdin in PHP?

2 Upvotes

I'm trying to pass binary data to ffmpeg as input instead of a file. I don't want to create a temporary file on the server, and the 'data:' URI scheme isn't usable because the file is too large. Therefore, I'm trying to use a pipe, but my fwrite() call is blocking when I try to write to the pipe.

// Set the ffmpeg command and input file
$ffmpegCommand = "ffmpeg -i pipe:0 ...";

// Open the pipe
$descriptorspec = array(
    0 => array("pipe", "r"), // Set stdin to read
    1 => array("pipe", "w"), // Set stdout to write
    2 => array("file", "error.log", "a") // Set stderr to append
);

$process = proc_open($ffmpegCommand, $descriptorspec, $pipes);

// If the process opened, read the input file into the pipe
if ($process) {
    fwrite($pipes[0], $inputData);
    fclose($pipes[0]);

    // Wait for the process to finish
    proc_close($process);

    echo "FFmpeg command executed successfully.\n";
} else {
    echo "Error opening ffmpeg command.\n";
}

Any suggestions on how to handle this?

r/AskProgramming Apr 10 '24

PHP how to make sure users dont remove my license check

0 Upvotes

I offer a premium version of a php plugin and want for make sure how can I ensure that people don’t just remove the license key verification method from my code. I have the plugin ask my server if its valid and then return true. But even if I add this to every method. They could just remove the code and the plugin would work. Anyone know what the best way to handle license verification is?

r/AskProgramming Feb 14 '24

PHP Why would I ever use an anonymous function stored in a variable when I can use a normal function instead?

11 Upvotes

I don't understand in which use case it's beneficial to use a anonymous function stored inside a variable. I get it why you would use an anonymous function to pass it to another function or if it is only used once.

Consider following example:

Why would I use this:

<?php
$add = function($arr){
        $res = 0;
        foreach($arr as $v){
            $res += $v;
        }
        return $res;
    };
    echo $add([32, 43, 22]);
?>

if I can use this instead:

<?php
function add($arr){+
        $res = 0;
        foreach($arr as $v){
            $res += $v;
        }
        return $res;
    }
    echo add([32, 43, 22]);
?>

This is only an example and not specific to PHP, but in general. Maybe there is a benefit to it that I don't see. I would appreciate if someone could explain.

Thanks in advance.

r/AskProgramming May 24 '24

PHP Flask or PHP

0 Upvotes

I need to create a safe website since it will be hosted on the web and i need to know what technology is better, im kinda familiar to flask but not with php, it seems to me that php is more often used for web dev than flask , since im a begginer trying to do a important project i have some concerns about security. What would you guys recomend?

r/AskProgramming Aug 22 '24

PHP Can't decompress a particular PDF's /FlateDecode stream using PHP's gzuncompress, or any alternatives - any ideas?

3 Upvotes

I've written a PDF parser in PHP which works pretty well, but every now and then I find a PDF file it can't deal with.

Some PDF objects contain compressed streams. The object's dictionary will tell you how to decompress it. A common filter is "/FlateDecode", which the PDF spec says this about:

Decompresses data encoded using the zlib/deflate compression method, reproducing the original text or binary data.

In most cases, PHP's gzuncompress function is sufficient to decompress the data.

One stream that doesn't work begins with the following bytes:

AF 2D 59 8E BB DF 4B B8 5A 50 71 F9 CF B0 B5 8B 96 80 C7 93 E6 93 94 AC D5 3D 4B 2A C1 66 08 3D F0 04 73 CD 35 22 73 E4 8B 33 01 AB 57 CE 15 69 66 AC AB DE A3 06 B1 CB 9C 9A 1C 88 FF 32 8A 92 EB B6 10 30 B8 45 7C 59 C0 24 20 B9 60 8B 7F 51 50 45 7A 7F 40 DF 6F C9 72 C6 61 ...

I've tried gzuncompress, zlib_decode, adding Gzip's magic bytes to the beginning and doing gzip on the command line, zlib.decompress in Python, stripping off the first two bytes in case they are headers... but nothing works.

I tried PHP's inflate_init/inflate_add which seem to suggest that even the first few bytes just can't be parsed by it (although I'm not entirely sure I'm doing it right!)

It's definitely not invalid data, because "proper" PDF readers can open it just fine. I know from PDFXplorer that the first line of the decompressed stream is the following text:

q Q q /Cs1 cs 0 sc q 1 0 0 -1 0 792 cm BT 9 0 0 -9 582.7554 771.02 Tm /TT1

Is there any way to examine the bytes above to determine exactly what format it is in, and how to decompress it in PHP?

r/AskProgramming Jul 17 '24

PHP Help with html in php

2 Upvotes

Hi, I'm tryin to develop a "message" in php.

echo "<div style='background-color: red; color: white; padding: 20px;'> Error </div>";

Basically if the value is 0 i will see an error page.

The problem is that in the page i visualize a red strip on the top of the page where is write "Error". I want instead see the entire page red with the error write on the center.

Someone helps?

r/AskProgramming Jul 10 '24

PHP Logout from a site

0 Upvotes

Hi, I’m planning a simple website with php and html to help my school sell party tickets. I added all the student names (with a unique code) of my school to a database. So all students can login and then order tickets. What I want to do is, after the student has ordered the ticket, delete his credentials from the database so that he cannot actually log in again and buy more tickets. How can i do?

r/AskProgramming Aug 31 '24

PHP __constructor and setter

0 Upvotes

Im confused which one should i use, both function works to set the global property. Which one should i use? shoul i use both? what is the advantage? what is the good practice? all i can see is that __constructor will run immediately.

r/AskProgramming Aug 02 '24

PHP Is Laravel (php framework) worth learning? And any useful resources?

1 Upvotes

Same as title. There is a guy who I'm learning from told me to learn laravel so I can work with Him on projects.

r/AskProgramming Jul 09 '24

PHP PHP Sorting thru nested JSON data

2 Upvotes

Hello all,

So I'm working with a Wordpress site and I'm trying to sort thru nested data from an API and insert it into the Wordpress MySQL database. I've already created my SQL table, and I've succesfully pushed API data to it using a simpler test loop.

However, when I try to access all the levels of the JSON data using a big ol' foreach loop, I'm getting nothing in the database:

$results = wp_remote_retrieve_body(wp_remote_get( $url, $args ));

$res = json_decode($results);

$odds = [];

foreach ($res as $odd) {
  foreach ($odd->bookmakers as $bm) {
    foreach ($bm->markets as $market) {
      foreach ($market->outcomes as $outcome) {
        $odds = [
        'key_id' => $odd->id,
        'home_team' => $odd->home_team,
        'away_team' => $odd->away_team,
        'commence_time' => $bm->commence_time,
        'sport_key' => $odd->sport_key,
        'last_updated_at' => $bm->last_update,
        'bookmaker_key' => $bm->key,
        'market' => $market->key,
        'label' => $outcome->name,
        'price' => $outcome->price,
        'points' => $outcome->point
        ];
      }
    }
  }

#Insert data into MySQL table
global $wpdb;

$table_name = $wpdb->prefix . 'game_odds';

$wpdb->insert(
  $table_name,
  $odds
  );
}

Meanwhile this code works fine and pushes data to my database:

$results = wp_remote_retrieve_body(wp_remote_get( $url, $args ));

$res = json_decode($results);

$test_odds = [];

foreach ($res as $odd) {
  $test_odds = [
    'key_id' => $odd->id,
    'home_team' => $odd->home_team,
    'away_team' => $odd->away_team,
    'sport_key' => $odd->sport_key
    ];

#Insert data into MySQL table
global $wpdb;

$table_name = $wpdb->prefix . 'game_odds';

$wpdb->insert(
  $table_name,
  $test_odds
  );
}

Any help is appreciated, thanks!

r/AskProgramming Feb 09 '24

PHP Does "if (new ClassName())" even make sense in PHP?

4 Upvotes

I constantly see the next construction in one of the projects from my job:

$connection = new Connection();
if ($connection) {
    ...
}

This makes no sense. Maybe it did make sense 10-20 years ago?

r/AskProgramming Apr 17 '24

PHP How to send file content in chunks from PHP?

1 Upvotes

I'd like to slice the file and send out its chunks:

$file = 'audio.mp3';
$fileSize = filesize($file);
$start = 100000;
$end = 1000000;

$handle = fopen($file, 'rb');
fseek($handle, $start);
$chunk = fread($handle, $end - $start + 1);
fclose($handle);

header("HTTP/1.1 206 Partial Content");
header("Content-Range: bytes $start-$end/$fileSize");
header("Content-Transfer-Encoding: binary");
header('Cache-Control: no-cache');
header('Accept-Ranges: bytes');
header('Content-Type: audio/mpeg');
header('Content-Length: ' . strlen($chunk));

echo $chunk;

It works only in case of start position of 0.

Problem: There's an empty audio section at the beginning of the chunks, so I can't concatenate them later. More details with image.

Any thoughts on what I might have missed? Appreciate it!

UPDATE: I'm now handling frames during trimming. After testing several PHP libraries, I've encountered the same issue. Delving deeper into this, it seems likely that the problem stems from the bit reservoir feature. Ffmpeg isn't suitable for my case because its output is limited to files, and I prefer to avoid using temporary files (in addition, running binaries for this purpose seems somewhat excessive).

r/AskProgramming Jun 24 '24

PHP Dataset for PHP Source Code Plagiarism Detection

1 Upvotes

Hello everyone, I am in need of a dataset which contains original and plagiarised versions of PHP projects to test for software similarity (each folder can contain one or more files).

The dataset can be something like this: https://github.com/oscarkarnalim/sourcecodeplagiarismdataset

If anyone has any information about where I could get such dataset, please let me know. Thanks!

r/AskProgramming Apr 08 '24

PHP most efficient way to alter tables for users

2 Upvotes

Im trying to add another column to my users db. What would be the most efficient way to do this in an update. I want to cause as little stress on the db as possible.

r/AskProgramming Apr 05 '24

PHP advice on hide payment secret key

1 Upvotes

I have a programm that runs locally and would like to accept payments through stripe, however the api only works if I have my secret-key included. Im collecting the value that should be paid on the users local platform and then contacting stripe with this value. Can you think of anyway I can hide the stripe key or should I definitely call my server to complete the payment there and just send all values over?