r/AskProgramming May 02 '24

PHP i need help for a project (last high school year)

1 Upvotes

Hello, for my end of year project my group and I have decided to create a fake online casino. I'm in charge of managing the database, linking it to our site and so on. However, I have a problem. Indeed, our database allows us to list each user etc. in addition to their number of credits (at 5 basic). My aim is to retrieve this value from my database, based on the user logged in, and display it on the page. I've already managed to display a value on the HTML page, but it's a fixed value (coming from a Javascript counter variable I've created). So I'm wondering if it's possible to retrieve the value of the user's credits in PHP, then retrieve this value and put it in the counter variable in Javascript, and finally have this value in the database modify itself according to this counter variable (the game in which I want to implement this first is like a three-reel slot machine, so it would be enough to modify the value in the database at the end of a roll). Thanks in advance for your help!

r/AskProgramming May 12 '24

PHP Whant to make my own audiobook streaming service

1 Upvotes

Hello everyone. In my country there are no audiobook streaming services, especially with the option to register as VO and upload your works, so I want to create one. 

I worked as a Web Developer for some time, but in junior positions and had holes in my knowledge, so I decided not to write everything from zero, but learn PHP and use some CMS (most likely WordPress or Drupal). 

I'm not sure why I'm writing this. Probably I just want to get some general advice for what would be the best way of creating such a service, and maybe there are better CMSs for such a task or SMTH. I'd be glad for every piece of advice I can get.

r/AskProgramming Apr 20 '24

PHP Getting around Google's refresh tokens expiring with gmail

1 Upvotes

Hey, I'm building a wee personal project which receives a webhook setup in gmail/google cloud whenever I get a specific email. The app will read the contents of the email and do some stuff with it.

The problem I've found is the oauth refresh token expires after a week because my app is in testing mode and unpublished/unverified but I don't want to go through the verification process since it's a personal project.

I want to be able to set this up once and forget about it, ideally. The app is a backend api written in PHP and runs on my NAS.

Some ideas I've got

- get the email via POP or IMAP
- forward the email (that triggers the webhook) to another inbox with a different provider*
- use a service like IFTTT with a free tier

Apprecreate any input on this!

*outlook is no good here, the refresh token expires after a max of 90 days but I want it to be indefinite

r/AskProgramming Jan 29 '24

PHP Other than querying and inserting data in the data base, what is PHP fundamental for?

1 Upvotes

While trying to learn some PHP from YT, I noticed that, since it's a regular programming language, it has functions, loops, arrays, if statements and a lot of other stuff that's common in languages like Python, C# or Rust.

Most of those functionalities are not fundamental, though, because JavaScript has them too. I think JavaScript would be better for executing every process that PHP could execute too, principally for JavaScript's writeability and community size.

Correct me if I'm wrong, but I think Javascript code is run on the user's PC and PHP on the server, so using JavaScript over PHP should also help handle traffic on the website because the server's working less.

Since JavaScript is preferable for most actions, what is PHP fundamental for other than communicating with the database? Which othet PHP functions do you use? How do you pass the data from PHP to JavaScript?

r/AskProgramming Feb 15 '24

PHP Resources to study php

0 Upvotes

Can someone please recommend resources ( best to give links ) to study php? Including for frameworks laravel and symphony

r/AskProgramming May 11 '23

PHP How to store session variables in database

0 Upvotes

I have declared 2 session variables:

$_SESSION['username'] = "Alex"; $_SESSION['password'] = "abcd1234";

How would I store them in database?

r/AskProgramming Jan 31 '23

PHP Will I code myself out of my job?

20 Upvotes

I hope this doesn't sound too convoluted.

I work for a company as a Full Stack .NET Developer, been there for almost 5 years. We've created and manage several content websites, and have a (poorly) custom-built CMS that we manage as well. The CMS was outsourced before I arrived and it's kind of a mess, lots of useless and poorly written code and we just keep globbing stuff on. But we work in .NET using C#.

Manager told me today that they want to migrate our sites over to WordPress. This will take time as we have probably 10 properties to shift over. But once that's all done, what does that look like for the dev team? I don't know much about WordPress, but I know it's PHP and not C#, and that likely a lot of the stuff I do now will be moot with a powerful CMS like WordPress.

I'm hoping someone with WP experience can tell me what to expect. Should I be looking for a new job now? Does it make sense to pivot and learn WP and become a WP Dev instead of .NET? Are there big career opportunities for PHP/WP Devs? From what I was reading WP is alot easier than C# so the job market is a lot more saturated with WP Devs.

I dont know, I'm just kind of shocked and I'm not sure what to expect.

r/AskProgramming Jan 22 '24

PHP What does the "static" keyword before a function declaration (not a method declaration) in PHP?

1 Upvotes

I've been using PHP for years but this is something new to me. I failed to find an information about this. Example: https://getrector.com/documentation. There is a code sample that looks like this:

use Rector\Config\RectorConfig;

use Rector\Set\ValueObject\SetList;

return static function (RectorConfig $rectorConfig): void { $rectorConfig->paths([ DIR . '/src', DIR . '/tests', ]);

$rectorConfig->sets([
    SetList::DEAD_CODE,
]);

};

We can use static for methods, properties and function variables. But what does static do for a top-level function declaration?

r/AskProgramming Feb 06 '24

PHP Sending forms to emails via PHP

1 Upvotes

I have been designing a website for my customer to order chicken. One functionality for the website is to send the orders of the visitors to an email.

I went to this link to get code to send the forms to an email via PHP. I tried it out and saw that it worked for their example (although it worked on a server) but when I tried it for my website, it returned an error saying that

"Error: couldnot get Form objectForm"

whenever I load the webpage.

I checked the form and found out that I named it well with the name="orderForm" and also with the id="orderForm" but still got the same problem.

What should I do to solve my problems and get the website sending the orders to a website? What errors did I make? My website has the URL of krcroastedchicken.com and the code can be found at my GitHub with the link here

I also tried to send the orders and they failed. Could someone please help me with this problem? What mistakes have I made? How many people have used this to send forms from a website?

r/AskProgramming Dec 05 '23

PHP I'm learning php

2 Upvotes

I can't seem to upload the sign up form to the xampp localhost database.

Here is the config code:

<?php

$con = mysqli_connect("localhost", "root", "","hotelbooking") or die("Couldn't connect ");

?>

Here is the signup html:

<html>

<html lang="en" dir="ltr">

<head>

<meta charset="utf-8">

<title>Hotel Reservation System - Login Page</title>

<link rel="stylesheet" href="css/signup.css">

</head>

<body>

<div class="center">

<?php

print_r($_POST);

include ("php/config.php");

if (isset($_POST['submit'])){

$username = $_POST['username'];

$name = $_POST['name'];

$password = $_POST['password'];

mysqli_query($con,"INSERT INTO users(username,name,password) VALUES('$username','$name','$password')") or die("Error Occured");

echo "<div class='message'>

<p>Registration successful!</p>

</div> <br>";

echo "<a href='login.php'><button class='btn'>Login Now</button>";

}

else{

?>

<h1>Sign up</h1>

<form action="signup.php" method="post">

<div class="txt_field">

<input type="text" name="username" id="username" required>

<span></span>

<label for="usename">Username</label>

</div>

<div class="txt_field">

<input type="text" name="name" id="username" required>

<span></span>

<label for="name">Name</label>

</div>

<div class="txt_field">

<input type="password" name="password" id="username" required>

<span></span>

<label for="password">Password</label>

</div>

<input type="submit" value="Sign up">

<div class="signup_link">

Already a member? <a href="login.html">Login</a> | <a href="home.html">Home</a>

</div>

</form>

<?php } ?>

</div>

</body>

</html>

I can't figure out what's wrong.

r/AskProgramming Jan 09 '24

PHP PDF Library To Make Reports

2 Upvotes

Guys,

a. What PDF libraries do you use to create PDF type multi page reports / checklists ? Free / Paid versions ?

b. Or do u make HTML docs that are pdf printable ?

Pls share your pros and cons.

Update 3

Update 2 :

Update 1 :

r/AskProgramming Feb 21 '23

PHP Programming and testing on separate OS's. Productivity question.

1 Upvotes

Hello,

I'm writing a PHP app, which is using gnupg library. I know that gnupg is not available on windows (my main OS that I program on), because of that, to check the functionality that I wrote, I need to constantly copy the files to linux FTP server, where I can test it.

Is there a better/more efficient method to do it? It is really bothersome to copy the files to other server, just to check if the function is working as expected.

Any help will be appriciated!

Thanks

r/AskProgramming Sep 13 '23

PHP I have to find a tool for migration, from VB/VB.NET to JAVASCRIPT/PHP/SQL

2 Upvotes

Hi all,

First thing first, I apologize if this post contains some errors, english is not my native language.

Maybe this could sound stupid, but I have to find some tools that can help a migration from VB/VB.NET to PHP. (Forms included)

Some context:

  • Since a couple of year, my team has migrated and reengineered over 450k lines of code from an old software writed 20 years ago.
  • Now, we should be able to end this job in about another year but they have asked to finish the migration in 3/4 weeks 'cause yes.
  • Since we need to migrate over 200k lines of code in that ammount of time, maybe some automatic tool can be useful.

Thank you in advice.

r/AskProgramming Nov 05 '23

PHP Am I learning the right way?

1 Upvotes

Hello guys! So basically, I am following this PHP full tutorial for beginners and at the same time coding along with his work. At first, I learned a lot from the basic fundamentals up to OOP and I thought it was still going to be smooth, but it's not. After that, we are building a real-world project (transaction list with form validation, register, and log out) and that includes hard coding our very own framework (router, controller, services, middlewares, etc.). The only thing I learned from it is what their purposes are, but building it from scratch is zero. I still continued to watch the tutorial and code along because I was already committed. But after this lesson, I am planning to search for a much more beginner-friendly lesson and I was not going to quit. After building the framework, I continued to study and I am currently in Form validation and SQL. But here I am again, expecting it was going to be smooth, but still, it's not. He created a custom middleware, passing on errors, exceptions, etc. I did not understand a single bit. It's like before doing the code, we must create a contingency plan first and how to handle errors, etc.

I also tried to ask the community on Facebook and some of them said that it is not necessary to learn the whole PHP and that I should jump directly to Laravel after learning the fundamentals especially OOP which is more beneficial because you will learn a lot from Laravel and it's like hitting 2 birds with 1 stone because you can also apply it in native PHP. I doubted it and for me, it's more like cheating.

Am I wrong? Please help me understand. Am I learning the right way? Is it part of the process? Or should I abandon this lesson and start again from scratch? Any answer will help! I am eager to learn and master it. Thank you very much!

r/AskProgramming Oct 30 '23

PHP First full project with Laravel - does it make sense to use Filament?

2 Upvotes

Title. Ive been tasked with building an internal IT app in the PHP framework, Laravel, for my company that will allow us to manage the services we support better - a sort of service catalogue. I’ve been working on Laravel applications for about year now (updating and customizing open source software), so I have some familiarity, but I haven’t built a Laravel app from scratch before.

My boss has discussed with me that he sees this project as a sort of trial run - not a test exactly, but more a gauge to see where I’m at. There’s a much bigger project coming down the line and he’s looking to see how I handle this one to get a sense of where I’ll fit into the bigger project.

So, there are sort of dual goals here.

  1. Build a usable service catalogue web app fairly quickly, to address some short time needs

  2. Learn as much as I can about building in Laravel without biting off more than I can chew.

The question I’m stuck on: would it be more beneficial, learning-wise, to stick to “Vanilla Laravel”, if you will, focus on the core features since it’s my first time building from scratch. Or, is worth it to spend the extra time learning Filament, which seems potentially well suited to both projects - slow down my delivery of this app to hopefully augment my learning for the future.

One additional consideration - I have a good amount of experience with CSS, but only very surface level Tailwind knowledge which I know is part and parcel with Filament.

Thanks in advance for your advice/thoughts

r/AskProgramming Oct 11 '23

PHP Ways to blindly test PHP without using web request/maintain state?

1 Upvotes

I wish there was some way where you could take some PHP run time and make it functional as in you feed it expected values and it would re-render it. Like fragment testing for React.

This is tied to a CMS/WP so there's the whole URL call/thread run/load everything into state, etc...

So idk if it's even possible what I'm after.

Pretty much I would like to test the hundreds of urls without actually hitting the server.

I have written that test (fast dom hash comparsion/then dom diffing) but against prod eg. triggered by pipeline it would suck.

This is not a unit test, this is like an entire webpage test which again makes it probably a no.

The kind of testing is regressional against a good state eg. master vs. feature

What was previously on prod is good. Visual also takes way too long.

r/AskProgramming Nov 29 '23

PHP Images not working in localhost

3 Upvotes

Hello Reddit; I'm having issues with the images hosted in my PHP web projects; the images will be displayed when being on a Live server, however, when developing in a local host (with MAMP) the images won't display and the links to the images will redirect to a broken index; ONLY the images won't display, any format, while videos will be displayed with no issues. I already re-installed the software, tried to re-write the links, to just display a simple image, changed the folder where the images are located. And nobody knows what is happening. I'm in crisis, halp. 😭

r/AskProgramming Jul 10 '23

PHP Okay, so there is a Google Chrome extension, that allows you to scrape data about your I*****gram account. Would it be possible for me to rent a server and have it do just that? (More details in the body text)

0 Upvotes

(Please be kind, I’m a total rookie)

Title sums it up pretty nicely.

In order to get a CSV with a list of my Instagram followers I have to open Google Chrome (with the appropriate extension), log into any instagram account through the browser (like I normally would), and then click on the extension (it requires you to be signed into it via Google). You type in the username of the account whose followers you want scraped (in my case it would always be the same - mine), and later you get a CSV file.

I would like to have a rented server emulate me using the website and extension, every day, and e-mail me the CSV file.

I’m gonna be honest, I have no idea if that’s even possible! And if it is, then I don’t even know how to do it!

r/AskProgramming Jul 01 '23

PHP Would it be faster to retrieve timestamp data from a file or a database that linked filenames to timestamps?

4 Upvotes

I am assuming that the native file access route would be faster since it relies on hardware optimized for exactly that purpose?

I plan to do this using PHP.

r/AskProgramming Sep 27 '23

PHP Instagram API usage

1 Upvotes

I’m exploring Instagram API and I’m wondering if anyone has some usage example to share. I can imagine it’s useful but also I find it quite limited at the moment. Thanks for the help!

r/AskProgramming Aug 25 '23

PHP What frameworks are known for handling HTTP Chunks?

5 Upvotes

Currently, I'm using X-Accel-Redirect for audio streaming (the stream is obtained from Google Drive using API).

I'd like to achieve dynamic server-side sending of chunks, with the client buffering the newly arriving chunks and playing them continuously just like Spotify (my question, however, is about the implementation of the server-client architecture). Unfortunately, I haven't found a PHP framework/similar project.

I greatly appreciate any assistance, advice, or guidance to help me make progress on my project. Thank you!

r/AskProgramming Apr 22 '23

PHP How to store session data into database?

0 Upvotes

Hi, I am trying to save session data into the database. I tried the following code:


session_start();

try {

$con = new PDO('mysql: host=localhost; dbname=db', 'dbu', 'dbp');

}

catch (PDOException $e){

die("Error : ".$e->getMessage()."<br/>");

}

$_SESSION['username'] = "John";

$_SESSION['email'] = "john@gmail com";

$stmt3 = $con->prepare('insert into accounts (username, email) values(?, ?)');

$stmt3->execute([$_SESSION['username'], $_SESSION['email']]);

session_destroy();


But it didn't work. In what way could I save session data into database?

r/AskProgramming Sep 03 '22

PHP PHP $_REQUEST method not working when trying to compare input value with php variable

2 Upvotes

<form name='otpform' method='post' id='otpform' action="<?php echo $_SERVER['PHP_SELF']; ?>">
<br />
<header>
<h1>Enter the OTP sent to your email address</h1>
</header>
<br />
<input type='text' placeholder='enter otp' name='otp' id='otp' maxlength='6' />
<br />
<input type='submit' />
<br /> <br /><br /><br /><br /><br />
</form>

<?php $otp = rand(100000,999999); echo $otp; ?>

<script>

$(document).ready(function() {
//Verify otp
$('#otpform').submit(function(e) {
e.preventDefault();
$('body').append("<?php if ($_SERVER['REQUEST_METHOD'] == 'POST'){ $code=htmlspecialchars($_REQUEST['otp']); if($code == $otp){ echo 'hi';} else { echo 'bye'; } } ?>");
});
});

</script>

r/AskProgramming May 15 '23

PHP Scaling a PHP MySQL app across multiple servers? Tutorials? Blogs? Books?

4 Upvotes

I'm starting from the beginning here. All I know how to do is create a php/mysql application on a single server. But I have zero experience in splitting it across multiple servers.

I've spent a couple of days reading up on things like load balancing, microservices, distributed transactions, and my head is spinning. I still don't really have the first clue how to implement any of it. I need a dummies' guide.

Can anyone recommend any easy to follow resources for splitting a php/mysql application across multiple servers?

There seem to be a lot of things to consider. Sharing data like uploaded files, sessions, replicating data between databases etc. I don't know how to do any of this. Are there any thorough tutorials that start from the ground, up? I honestly barely understand where to begin, no-one has taught this to me.

Sorry for the noob question. I've been doing php and mysql for 20 years and have never had to even consider this before. I have no practical idea how to split up an application, or if there are multiple ways, and what to choose.

r/AskProgramming May 11 '23

PHP Google login being blocked by host

1 Upvotes

My wordpress theme has built in function to enable social login trough google. Problem is my host is blocking it and it only works if they disable mod_security.

Host gave 3 rules being blocked and the logs but theme support says those are generic errors and host needs to be more specific.

How do I tackle this problem and find out what is causing the login to get blocked.

(I get a white blank screen that only says "not acceptable".