/r/PHPhelp
This subreddit is for anyone who has questions about their PHP code.
Please read and understand the rules before creating a post.
Post specific problems or questions you have about PHP or your code.
Review our github to see if your question already has a great answer.
If someone answers your question, please mark your post as SOLVED.
/r/PHPHelp RULES:
1. Help us help you! Provide details about your question and be as specific as possible. When supplying code, preferably use PasteBin or similar.
2. Be nice Golden rule, people. If you believe someone is wrong, kindly inform them why you think so. It's possible you are also wrong. BE NICE!
3. Participate Posts that are only intended to get others to solve your problem add nothing to the community. Actively participate when you make a post by answering questions and sharing solutions.
4. Use a meaningful title Titles like: "PHP Help", "Help please", "Beginner question", or "I need some help with resolving this issue" are not good and not meaningful. Please include relevant info.
5. Don't delete an answered post People may be searching to solve a similar problem in the future. Don't take the provided answers away from them!
6. No malicious/illegal software Don't ask for help with phishing software, for example.
7. Self-promotion and/or linkdropping rules Our community adheres to the Reddit Self-Promotion Guidelines. Please become familiar with these guidelines as we, as moderators, will use them to remove content that we deem to violate these guidelines.
8. No job postings (For Hire or Hiring)
9. MARK YOUR POST AS SOLVED If your post has been solved, mark it as so by clicking Flair
-> Solved
.
CODE FORMATTING:
For inline code, use `backticks` to look like this
.
For a moderate amount of code, put it on separate lines, and prepend each line with four spaces, like this:
<?php /* code goes here */ ?>
For a lot of code, use PasteBin or something similar.
Upcoming PHP Conferences:
For a full list of conferences see the list on php.net.
Learning:
Examples:
Related subreddits:
/r/PHPhelp
I am trying to inject a session ID into Selenium so the browser instantly has access as that user, rather than having to login through the browser for each test which is obviously slow.
I will have hundreds of tests, and I want to be able to toggle between uses to run the test. I've been trying code like this below but can't get it to grant Selenium access. I have confirmed the cookie is available when I send Selenium to the page.
public function testDashboardAccess() {
//log the user in
$user = User::where('id', 1)->first();
auth()->login($user);
$sessionId = session()->getId();
$encryptedSessionId = encrypt($sessionId, false);
//attempt 1: inject cookie into Selenium (using just the standard $sessionId)
$this->webDriver->manage()->addCookie(['name' => config('session.cookie'), 'value' => $sessionId, 'domain' => '.app.myurl.com', 'path' => '/', 'secure' => false]);
//attempt 2: inject cookie into Selenium (using just the encrypted $encryptedSessionId )
$this->webDriver->manage()->addCookie(['name' => config('session.cookie'), 'value' => $encryptedSessionId, 'domain' => '.app.myurl.com', 'path' => '/', 'secure' => false]);
}
today i tried downloading my composer then, overthinked it i deleted the files then i tried to install it again and tried cmd then i tried this composer create-project laravel/laravel app-name but it gave me "Failed to download laravel/laravel from dist: The zip extension and unzip/7z commands are both missing, skipping.
The php.ini used by your command-line PHP is: C:\xampp\php\php.ini
Now trying to download from source"
git was not found in your PATH, skipping source download
i'm still learning and still in college 2nd year
I've mostly worked on backend operations but now and finding myself assisting people with legacy frontend applications. I am looking for guidance on how to organize such projects. Ideally, we would just start fresh but budgets and other factors means these applications must be upgraded in parts.
For one project, there are over 3000 PHP files and some 1.2M lines of code. Much of the code is commented out, sometimes with explanation but often not. We estimate about 500K lines of code that is active but not sure how much is in use in the application.
The application is mainly organized into one major application component per file, however, that file may have includes of includes of includes (found one path 6 levels deep only to reference a string value).
To further make a mess of things, HTML is embedded into the code via string concatenation. This is further complicated by numerous if/then statements to handle various user levels, mobile/desktop views, etc.
We experimented with custom classes but we often find we have to include methods or objects in the class where it does not belong. We would end up writing a lot of code to do simple things in an effort to integrate the class back into the legacy app.
Also, we would like to get the app into some type of framework so that it is easier to maintain.
For this project, Symfony is preferred by the customer as they have some in-house experience with managing templates.
We looked into using the Legacy Bridge feature immediately but we do not think that is possible due to the state of the existing code. A large portion of the app is still on PHP 5.6. We don't want to build on a legacy version of Symfony.
So for now, we are starting to extract HTML from the code by just using Twig. This is helping us better modularize the code and I hope will allow use to move into Symfony later on.
We've handled a number of refactoring cases but the state of this code is such a mess it is challenging.
We've not event attempted to run this through a refactoring tool yet. PHP CodeSniffer's compatibility module returned so much stuff you would not know where to start. We also used Synk.io to look for security issues and spent some time patching the critical issues in the existing code.
Please let me know if you have any tips, tools or suggestions.
Hi all,
Sorry, but this will be a long post. To give some context, I have a family member who owns a car dealership. He currently has a website that was built and is maintained by a company that specializes in making dealership websites, but he pays a lot per month for the entire thing, so I’d like to make him a website so that all he’d have to pay for is his domain and a hosting, while I’d take care of doing any changes he wants and maintaining it (for free ofc).
Basically, the website would be to display his inventory with different filters (make, model, price, etc.), have different forms to contact him or request financing info, mobile + desktop version, multilang, an Admin panel to add new cars, etc.
I’m fairly good with pure PHP and have some basic knowledge of Laravel. I recently found out about a Laravel library/component called FilamentPHP that I could use to make the Admin panel, and it’s really inspired me to make this project using Laravel.
I had a couple questions though that I hope you can help me with.
Is using Laravel for this project a good idea, or should I go with something other than Laravel/PHP?
Is using FilamentPHP a good idea for the Admin panel where he’d add new cars? Can FilamentPHP be used for the front-end too, or is it better just for the Admin panel? Or maybe something other than Filament for the Admin panel?
What would you recommend I use for the front-end? Should I go with Blade, or Livewire, or something else? Maybe a front-end framework like Vue.js, and maybe pairing it with Inertia.js (which I’m ngl, I’m still not sure what it is)?
Regarding hosting, what would be best? I read about a thing called Laravel Forge, but I’m not quite sure what it is/does?
Are there any libraries that you recommend I should, or must, install in my project based on the features I want to implement?
And for the dev environment, I use WAMP for my normal PHP projects, is it okay to use for Laravel projects too? Or is it better to go with something else? I recently learned about Laravel Herd (though MySQL is apparently behind a paid version), and Laragon, idk if those are good options?
In any case, sorry for the very long post and the many questions, but I really want to get this right for him. I hope I haven’t forgotten any questions. If you have any recommendations for me, I’d love to hear them!
Thank you very much for any help you can provide me!
Hey,
So I don't see many jobs in PHP/Laravel (or maybe I don't know how to look for one) in Israel.
Almost everything for web is NodeJS/React jobs
Can you guys give me some tips to find a job after I finish my projects? I prefer one I can work from work and I decide the hours
Thank you!
Hi all!
With over 11 years of experience working in PHP, I had never ventured into open-source development, until now... For the yearly r/adventofcode challenge, I created a Laravel (scaffolding) package. However, my experience in open source is virtually non-existent.
I have 2 concrete questions;
what should be defined in the composer require list? For example, I did include "illuminate/support", however, what if I don't? Would this create issues with newer (or older) versions of illuminate/support?
how to handle a session cookie: Right now, I’m asking the user to retrieve their session cookie from the developer tools in their browser, but this feels like a hassle. Is there a "smart" way to retrieve this cookie automatically, for example using CURL or Guzzle?
I’d really appreciate it if anyone could provide feedback on my code. If you’re interested, I’d really appreciate it! :)
- The package: https://github.com/mjderoode/advent_of_code_helper
I'm pulling my hair here. Customer's Laravel seems to create a property out of thin air.
I've grepped several times through code base and database backups but I can't find where the property *discount_percent* is defined, yet in template it works.
Any ideas?
From blade, this works:
...
</tr>
@if($reservation->discount_percent)
<tr>
<td class="td-title">Discount: </td>
<td>{{$reservation->discount_percent}}%</td>
</tr>
@endif
<tr>
...
This is from the controller
public function test2()
{
#$reservation = Reservation::orderBy('id', 'desc')->first();
$reservation = Reservation::findOrFail(804);
$reservation->start_time = $reservation->start_time->setSecond(0);
$reservation->end_time = $reservation->end_time->setSecond(0);
$view = "emails.pdf.created-eastPDF";
$fileName = $reservation->customer->firstname . '-' . $reservation->customer->lastname . '-' . now()->timestamp . '.pdf';
$pdf = Pdf::loadView($view, ['reservation' => $reservation, 'vat' => '1234']);
echo "<pre>\n"; var_export( $reservation ); exit;
return $pdf->stream($fileName);
}
Controller setup
namespace App\Http\Controllers;
use App\AgencyCode;
use App\Customer;
use App\Http\Requests\GetIndexRequest;
use App\Http\Requests\TuiReservationRequest;
use App\Mail\RegisterUser;
use App\Mail\ReservationCreated;
use App\Mail\Temp\ToBeDeleted;
use App\OneTimeDiscountCodes;
use App\OpenClosedDay;
use App\ParkingArea;
use App\Reservation;
use App\Services\AutopayBooking;
use App\Services\NewCustomerRequestValidation;
use App\Services\PaymentHighway;
use App\Transformers\OpenClosedDayTransformer;
use App\TuiReservation;
use App\UncommittedPayments;
use Carbon\Carbon;
use Illuminate\Contracts\Support\Renderable;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Validator;
use League\Fractal\Manager;
use League\Fractal\Resource\Collection;
use Barryvdh\DomPDF\Facade\Pdf;
/**
* @OA\Info(
* version="1.0.0",
* title="Client Documentation",
* description="Client enpdpoint description",
* @OA\Contact(
* email="admin@admin.com"
* ),
* @OA\License(
* name="Apache 2.0",
* url="http://www.apache.org/licenses/LICENSE-2.0.html"
* )
* )
*
* @OA\Server(
* url="https://client.local",
* description="Party API Server"
* )
*
* @OA\Server(
* url="http://client.local",
* description="Party API Local"
* )
*/
class HomeController extends Controller
{
protected $fractal;
protected $autoPay;
protected $paymentHighway;
public function __construct()
{
$this->fractal = new Manager;
$this->autoPay = new AutopayBooking;
$this->paymentHighway = new PaymentHighway;
}
public function testEmail()
reservation
App\Reservation::__set_state(array(
'guarded' =>
array (
),
'dates' =>
array (
0 => 'start_time',
1 => 'end_time',
2 => 'transaction_at',
3 => 'email_sent_at',
4 => 'deleted_at',
),
'casts' =>
array (
'all_discounts_info' => 'array',
),
'connection' => 'pgsql',
'table' => 'reservations',
'primaryKey' => 'id',
'keyType' => 'int',
'incrementing' => true,
'with' =>
array (
),
'withCount' =>
array (
),
'perPage' => 15,
'exists' => true,
'wasRecentlyCreated' => false,
'attributes' =>
array (
'id' => 804,
'customer_id' => 7,
'start_time' => '2024-03-01 02:00:00',
'end_time' => '2024-03-09 01:30:00',
'vehicle_type' => 'el_car_only',
'vehicle_reg_nr' => '',
'price' => 8480,
'created_at' => '2024-02-28 10:52:57',
'updated_at' => '2024-03-09 02:00:03',
'reference' => '',
'status' => 'OK',
'transaction_id' => '854ee7a3-9a1d-4739-95b5-275ae457c4a9',
'transaction_at' => '2024-02-28 08:53:18',
'user_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Safari/605.1.15',
'payment_method' => 'Visa',
'vehicle_status' => 'FINISHED',
'agency_code_used' => NULL,
'tehden_sale_id' => NULL,
'email_sent_at' => '2024-02-28 10:53:21',
'parking_area' => 'east',
'autopay_booking_id' => '5964553015787520',
'parking_area_id' => 5,
'discount' => '0.8',
'discount_type' => 'LOYAL',
'discount_info' => NULL,
'deleted_at' => NULL,
'all_discounts_info' => '[{"type":"LOYAL","description":"Frequent customer checkbox is checked"}]',
'pdf_link' => 'https://s3.eu-central-1.amazonaws.com/...pdf',
'new_discount_type' => NULL,
),
'original' =>
array (
'id' => 804,
'customer_id' => 7,
'start_time' => '2024-03-01 02:00:00',
'end_time' => '2024-03-09 01:30:00',
'vehicle_type' => 'el_car_only',
'vehicle_reg_nr' => '',
'price' => 8480,
'created_at' => '2024-02-28 10:52:57',
'updated_at' => '2024-03-09 02:00:03',
'reference' => '',
'status' => 'OK',
'transaction_id' => '854ee7a3-9a1d-4739-95b5-275ae457c4a9',
'transaction_at' => '2024-02-28 08:53:18',
'user_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.1 Safari/605.1.15',
'payment_method' => 'Visa',
'vehicle_status' => 'FINISHED',
'agency_code_used' => NULL,
'tehden_sale_id' => NULL,
'email_sent_at' => '2024-02-28 10:53:21',
'parking_area' => 'east',
'autopay_booking_id' => '5964553015787520',
'parking_area_id' => 5,
'discount' => '0.8',
'discount_type' => 'LOYAL',
'discount_info' => NULL,
'deleted_at' => NULL,
'all_discounts_info' => '[{"type":"LOYAL","description":"Frequent customer checkbox is checked"}]',
'pdf_link' => 'https://s3.eu-central-1.amazonaws.com/...pdf',
'new_discount_type' => NULL,
),
'changes' =>
array (
),
'dateFormat' => NULL,
'appends' =>
array (
),
'dispatchesEvents' =>
array (
),
'observables' =>
array (
),
'relations' =>
array (
'customer' =>
App\Customer::__set_state(array(
'guarded' =>
array (
),
'hidden' =>
array (
0 => 'password',
1 => 'remember_token',
),
'casts' =>
array (
'email_verified_at' => 'datetime',
),
'connection' => 'pgsql',
'table' => 'customers',
'primaryKey' => 'id',
'keyType' => 'int',
'incrementing' => true,
'with' =>
array (
),
'withCount' =>
array (
),
'perPage' => 15,
'exists' => true,
'wasRecentlyCreated' => false,
'attributes' =>
array (
'id' => 7,
'firstname' => 'TEst',
'lastname' => 'User',
'email' => 'test.email@gmail.com',
'phone' => '',
'street_address' => NULL,
'post_index' => NULL,
'post_office' => NULL,
'email_verified_at' => NULL,
'marketing_enabled' => false,
'remember_token' => NULL,
'created_at' => '2020-03-13 15:02:12',
'updated_at' => '2024-02-28 11:19:01',
'pin_code' => 259669,
'token' => '9439382c8a62b925d513a4d85774ca09729cf69666b1b58b499f4774658faafe',
'persistent' => 0,
'last_used_device_id' => NULL,
'customer_number' => NULL,
'loyal' => true,
),
'original' =>
array (
'id' => 7,
'firstname' => 'TEst',
'lastname' => 'User',
'email' => 'test.email@gmail.com',
'phone' => '',
'street_address' => NULL,
'post_index' => NULL,
'post_office' => NULL,
'email_verified_at' => NULL,
'marketing_enabled' => false,
'remember_token' => NULL,
'created_at' => '2020-03-13 15:02:12',
'updated_at' => '2024-02-28 11:19:01',
'pin_code' => 259669,
'token' => '9439382c8a62b925d513a4d85774ca09729cf69666b1b58b499f4774658faafe',
'persistent' => 0,
'last_used_device_id' => NULL,
'customer_number' => NULL,
'loyal' => true,
),
'changes' =>
array (
),
'dates' =>
array (
),
'dateFormat' => NULL,
'appends' =>
array (
),
'dispatchesEvents' =>
array (
),
'observables' =>
array (
),
'relations' =>
array (
),
'touches' =>
array (
),
'timestamps' => true,
'visible' =>
array (
),
'fillable' =>
array (
),
'rememberTokenName' => 'remember_token',
'enableLoggingModelsEvents' => true,
'oldAttributes' =>
array (
),
)),
),
'touches' =>
array (
),
'timestamps' => true,
'hidden' =>
array (
),
'visible' =>
array (
),
'fillable' =>
array (
),
'enableLoggingModelsEvents' => true,
'oldAttributes' =>
array (
),
'forceDeleting' => false,
))
Hi everyone,
I’m a frontend dev using Astro and PocketBase to build a project. PocketBase has been great because it comes with everything I need right out of the box: auth, CRUD operations, SQLite, built-in password reset and email verification, and even an easy GUI for managing everything. Backups are simple too, which has been a lifesaver. The only thing I’m really missing is smooth integration with payment platforms.
I’ve been hearing a lot about Laravel and wondering how it compares. Does Laravel have a similar developer experience? Are there any packages that make it feel as seamless as PocketBase, especially for things like auth, CRUD, and managing the database? Also, how’s the DX overall—easy to set up and use, or does it have a steep learning curve?
Would love to hear your thoughts, especially if you’ve used both!
I tried adding a pagination system to my search engine and it worked, but the results only appear on the first page. How do I fix the code so that the results appear on the other pages?
Complete code: https://jsfiddle.net/qm07v3et/
How I made the pagination system:
$limit = 10;
$count_query_string = "SELECT COUNT(*) FROM websites WHERE ";
foreach ($site_description as $word) {
$condition = "(site_description LIKE :word OR site_link LIKE :word OR site_title LIKE :word) OR ";
$query_string .= $condition;
$count_query_string .= $condition;
$params[':word'] = '%' . $word . '%';
}
$count_query_string = substr($count_query_string, 0, -3);
$page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
$offset = ($page - 1) * $limit;
$query_string .= " LIMIT :limit OFFSET :offset";
$stmt = $pdo->prepare($query_string);
foreach ($params as $key => $value) {
$stmt->bindValue($key, $value, PDO::PARAM_STR);
}
$stmt->bindValue(':limit', (int)$limit, PDO::PARAM_INT);
$stmt->bindValue(':offset', (int)$offset, PDO::PARAM_INT);
$stmt->execute();
$results_count = $stmt->rowCount();
$total_results_stmt = $pdo->prepare($count_query_string);
foreach ($params as $key => $value) {
$total_results_stmt->bindValue($key, $value, PDO::PARAM_STR);
}
$total_results_stmt->execute();
$total_results = $total_results_stmt->fetchColumn();
$total_pages = ceil($total_results / $limit);
echo '<div class="pagination">';
for ($i = 1; $i <= $total_pages; $i++) {
echo '<a href="?page=' . $i . '">' . $i . '</a> ';
}
echo '</div>';
I'm following a laracast laravel tutorial, and I'm running a 'code along' project, and I have the error above. I literally spent 4 hours researching and trying to troubleshoot it but could not find a solution. Does anyone know how to solve this problem?
What are the differences between using Raw SQL Query vs Query Builder Class in CodeIgniter? Am I developing a bad habit if I keep on using Raw SQL queries instead of the query builder? Does the query builder class provide more security when interacting with the database?
Hello. I'm following a tutorial on YouTube for a project I'm working on.
However, following these steps made me realize I don't know how to structure a PHP web app. Like, what does index.php
do? Which folders am I supposed to create and what do they hold? When do I make a feature its own dedicated file and when do I simply insert it into an existing one?
Can you provide me with a resource for how to learn about this?
I was making a program with PHP and during testing I got a fatal error saying Fatal error: Uncaught PDOException: could not find driver in C:\Users\****\public_html\Login Tutorial\login-manager.php :10 Stack trace: #0 C:\Users\****\public_html\Login Tutorial\login-manager.php(10): PDO->__construct('mysql:host=loca...', 'postgres' , Object(SensitiveParameterValue)) #1 {main} thrown into C:\Users\****\public_html\Login Tutorial\login-manager.php on line 10.
In line 10 I wrote $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Subsequently I went to check on phpinfo and noticed that next to PDO Drivers it says no-value. I don't know how to fix it, I've already tried removing the ";" before extension=pgsql, extension=pdo_pgsql etc.
PS: My operating system is Windows 11
So I'm on PHP 8.4 RC4 right now and I was updating my code to work with HTMLDocument
instead of DOMDocument
when I noticed this error:
Fatal error: Uncaught TypeError: DOMXPath::__construct(): Argument #1 ($document) must be of type DOMDocument, Dom\HTMLDocument given ...
Not being able to do XPath queries on the tree structure would make me stay on DOMDocument
, which would be unfortunate, but then in the RFC they do mention updating DOMXPath
, so is that still coming or what is the status with that? I could not find more information on any of this, which is why I'm reaching out here.
Hey,
So I'm a new to coding/php/laravel.
I want to watch my project on my phone also. I'm using Herd (project-name.test in browser to watch the project)
How can I watch my project from my phone?
Hi there! I have a pretty big openapi specification, over 5k lines long. I started splitting it into more manageable parts. If i reference a component from a different file, PhpStorm higlights this as an error, it can't simply undestand that there is a component in different file. Any plugins that can help me with this? Or solution how to work with big specification file? My PhpStorm really slows down when i open the specification, it's very hard to work when specification is open to the point i loose my train of thought while waiting for some other file to open.
For the reference, i use v 3.0.2 openapi, and i have OpenApi Specification plugin enabled.
Summary:
install odbc driver to a MacOS Silicon chip device to access azure cloud database using Xampp apache based website.
In detail explanation:
My friend has a macbook with M2 chip while im using a Windows 11 laptop.
For one of our university project we are to build a website using: Html, CSS, JS, PHP
we chose Azure SQL Serverless Database so we have a common db to work with. the issue with MacOS is that with the new architecture the odbc driver installation is a bit of a mess.
Lots of sources saying that to install ODBC using homebrew but the issue is, XAMPP apache uses its own directory not the opt/homebrew
now we are stuck process after install the sqlsrv, pdo_sqlsrv
we were following AI instructions because its hard to find a solid source and his php.ini got
extension=pdo_sqlsrv.so
extension=sqlsrv.so
extension=odbc.so
extension=pdo_odbc
we were able to install the sqlsrv, pdo_sqlsrv to the xampp directory some code like
/Application/XAMPP/xamppfiles/etc/ pecl install sqlsrv pdo_sqlsrv
but the issue is eventhough the above 2 files gets loaded, the odbc not get found because its in another direcotry.
how do i install the odbc 18 to the xampp directory in MacOS?(have a weird feeling that even after this wont be enough)
we have a testing test.php file that gives the phpinfo() result.
clear instructions to resolve this issue is greatly appreciated.
I'm using bluehost and I'm in the terminal. I ran the command "composer require stripe/stripe-php" and I received this error "In GitDownloader.php line 230:
Failed to execute git status --porcelain --untracked-files=no
fatal: unknown index entry format 0x77730000".
I have the Composer version 2.6.5.
I'm at a lost. Before that, I was using the twilio package and I never got any problems.
N.B.: If it is of any use here is the full message after I run the command "composer require stripe/stripe-php
./composer.json has been updated
Running composer update stripe/stripe-php
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Package operations: 1 install, 1 update, 18 removals
- Syncing twilio/sdk (8.3.7) into cache
In GitDownloader.php line 230:
Failed to execute git status --porcelain --untracked-files=no
fatal: unknown index entry format 0x77730000
require [--dev] [--dry-run] [--prefer-source] [--prefer-dist] [--prefer-install PREFER-INSTALL] [--fixed] [--no-suggest] [--no-progress] [--no-update] [--no-install] [--no-audit] [--audit-format AUDIT-FORMAT] [--update-no-dev] [-w|--update-with-dependencies] [-W|--update-with-all-dependencies] [--with-dependencies] [--with-all-dependencies] [--ignore-platform-req IGNORE-PLATFORM-REQ] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--apcu-autoloader-prefix APCU-AUTOLOADER-PREFIX] [--] [<packages>...]"
Hello, y’all. I have a xampp/lampp project that’s a couple years old. During the beginning, I made the executive decision to place my git root at /xampp/htdocs
as that seemed appropriate. I have recently been leveraging git worktrees and quite like the flow! Is there a way I can move my xampp project to also use them?
Note: I do have some require statements like require_once “/common/auth.php”
, hence my iffy-ness on it.
Further more, for my general curiosity, did I make the right choice with having htdocs as my root? Is there a better way?
Anyways, I’m not looking for a step-by-step just a general nudge. Any opinions or tidbits are welcome!
Not sure if it's my PHP code at fault, I get the else statement printed, so I don't know where I made a mistake.
I followed a YT tutorial from Excellent Consultancy, but the if statement in PHP throws an else portion.
I have no idea how this works and Google's documentation is very convoluted to me.
Here's my code:
<?php
session_start();
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$recaptcha_url = "https://www.google.com/recaptcha/api/siteverify";
$recaptcha_secret = "actual_secret_key";
$recaptcha_response = $_POST["g-recaptcha-response"];
$recaptcha = file_get_contents($recaptcha_url . '?secret=' . $recaptcha_secret . '&response=' . $recaptcha_response);
$recaptcha = json_decode($recaptcha, true);
if ($recaptcha['success'] == 1 && $recaptcha['score'] >= 0.5 && $recaptcha['action'] == 'submit') {
echo "Success!";
} else {
echo "Failure...";
}
}
<script async src="https://www.google.com/recaptcha/api.js"></script>
<script>
function onSubmit(token) {
document.getElementById("form").submit();
}
</script>
<div class="divM">
<button class="formButton headers" type="submit" name="submit" id="submit"
data-sitekey="6LfJqnwqAAAAAMnzFPbrPwD1txJpljqh5wCli-Lk"
data-callback="onSubmit"
data-action="submit">Submit</button>
</div>
<form class="form" action="test.php" method="POST" id="form">
...
Hello all, I'm trying to write some code to allow users to be able to authenticate using AD with phps ldap module but I'm having trouble.
I've tried a couple things like ignoring the cert all together (didn't work) and then using the set_option to point to the cert after fetching it. That doesn't seem to work either for some reason. When i point to it via the path it says unable to verify locations, but they're valid locations on disk. So I'm at a loss as to what to do, can someone please provide any guidance? Much appreciated!
<?php
// Valid creds
$ldapDn = "uid=myuser,dc=example,dc=com";
$ldapPassword = "abc123";
ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7);
// I tried doing the connect before these 2 lines and then passing that in as the first parameter and that still doesn't work. Plus the guide that I'm using says to do it this way as well: https://github.com/heiglandreas/ldap_cert_test?tab=readme-ov-file
// I've also tried the path with single "/" and "\", neither works.
ldap_set_option(null, LDAP_OPT_X_TLS_CACERTDIR, 'C:\\Apache24\\htdocs');
ldap_set_option(null, LDAP_OPT_X_TLS_CACERTFILE, 'C:\\Apache24\\htdocs\\ldapCert.pem');
$ldapCon = ldap_connect("ldaps://ldaps.example.com:636");
ldap_set_option($ldapCon, LDAP_OPT_REFERRALS, 0);
ldap_set_option($ldapCon, LDAP_OPT_PROTOCOL_VERSION, 3);
//var_dump($ldapCon);
if(ldap_bind($ldapCon, $ldapDn, $ldapPassword)){
echo "Succesfully Authenticated";
}
else {
echo "An error has occured";
echo ldap_error($ldapCon);
// Show the LDAP error message for more details
}
?>
Error message when specifying path:
attempting to connect:
connect success
TLS: could not load verify locations (file:`C:\Apache24\htdocs\ldapCert1.pem',dir:`C:\Apache24\htdocs').
TLS: error:05800088:x509 certificate routines::no certificate or crl found crypto\x509\by_file.c:251
ldap_err2string
Warning: ldap_bind(): Unable to bind to server: Can't contact LDAP server
Error message when NOT specifying path:
TLS certificate verification: Error, unable to get local issuer certificate
TLS: can't connect error: 160000069: STORE routines::unregistered scheme.
I accidentally deleted a user's data before logging out. Normally if I log out and then delete the user data. It won't happen. But this time I forgot to press logout. So this happened. Can anyone help me fix it? -------------------------------------------------------------------------------------- # users.php <?php session\_start(); include\_once "config.php"; $outgoing\_id = $\_SESSION\['unique\_id'\]; $sql = "SELECT \* FROM users WHERE NOT unique\_id = {$outgoing\_id} ORDER BY user\_id DESC"; $query = mysqli\_query($conn, $sql); $output = ""; if(mysqli\_num\_rows($query) == 0){ $output .= "There are no users in the system."; }elseif(mysqli\_num\_rows($query) > 0){ include\_once "data.php"; } echo $output; ?> -------------------------------------------------------------------------------------- -------------------------------------------------------------------------------------- data.php" [enter image description here](https://i.sstatic.net/4m9wkGLj.png) -------------------------------------------------------------------------------------- Warning: Undefined variable $row in C:\xampp\htdocs\users.php on line 22 Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\users.php on line 22 Warning: Undefined variable $row in C:\xampp\htdocs\users.php on line 22 Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\users.php on line 22 Warning: Undefined variable $row in C:\xampp\htdocs\users.php on line 23 Warning: Trying to access array offset on value of type null in C:\xampp\htdocs\users.php on line 23
Hey I have a php project in which I’m using MySQL database also the main project has a sub part which is basically a chat app it’s simple just a users page and one to one private chat and here I’m using ajax but we are expecting to decrease the server load cause by polling what should be the best alternative please share your recommendations on this.
I'm working on a school project where we are to create a website for a beermachine that we need to connect to via OPC-UA, to be able to control the machine remotely. We are writing the website in a Laravel project using PHPstorm, since that's what we've been taught during the semester.
For connecting to the machine, Eclipse Milo has been suggested to connect with the OPC-UA server, but Milo does not work with PHP project as far as we can tell. We've been looking for other alternatives but the libraries we find either no longer exist (like php-opcua) or cost money (like QuickOPC).
Does anyone have any other suggestions for libraries we can use, or is it a futile endeavour?
We would like to avoid having to make REST api's.
I have already checked for following libraries and extensions but none of them are working.
If anyone has better alternate solution, please suggest me. I am planning to use Laravel 11 so it would be great to have relevant solution to it.
Thanks in advance.
For my class project, we're supposed to create a form for people to sign up their dog for a class. I keep getting the "undefined index" error for lines 20-24 (it starts under the error reporting line) when I open the page. I made sure multiple times I had the right spelling in the PHP variables and HTML code within the input name attributes, but I can't figure it out, even though it worked completely fine before without changing it. Also, I'm not sure if I set up the mail() function correctly, it worked once using my college email, but I didn't get anymore after testing it multiple times, or with other emails.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Class Registration</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<main>
<!-- Start PHP script -->
<?php
//Add error reporting
ini_set("display_errors", 1);
error_reporting(E_ALL);
$first_name = $_POST["first_name"];
$last_name = $_POST["last_name"];
$email = $_POST["email"];
$dog_breed = $_POST["dog_breed"];
$phone_number = $_POST["phone_number"];
// Print some introductory text & image:
echo "<h1>Registration Form</h1>
<img src=\"images/dogs.jpg\" class=\"responsive\" alt=\"Shih Tzu(left) and a Daschund(right)\" title=\"Shih Tzu(left) and a Daschund(right)\">";
echo "<p>Register for our <b>FREE</b> \"Your Healthy Dog\" class! We will have presenters from local pet supply stores,
healthy dog treats and food, supplements to support your dog's immune system, and healthy treats for humans too!</p>";
echo "<p>Register below to join in on the fun and we will be contacting you via email with the date and time.</p>";
echo "<h2 class=\"center\">Keep Wagging!</h2>";
// Check if the form has been submitted:
$problem = false;
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (empty($_POST['first_name'])) {
print ("<p class=\"error\">Please enter your dog's first name.</p>");
$problem = true;
}
if (empty($_POST['last_name'])) {
print ("<p class=\"error\">Please enter your last name.</p>");
$problem = true;
}
if (empty($_POST['email']) || (substr_count(
$_POST['email'],
'@') != 1)
) {
print ("<p class=\"error\">Please enter your email address.</p>");
$problem = true;
}
if (empty($_POST['dog_breed'])) {
print ("<p class=\"error\">Please enter your dog's breed.</p>");
$problem = true;
}
if (!is_numeric($_POST['phone_number']) && (strlen($_POST['phone_number']) < 10)) {
print ("<p class=\"error\">Please enter your phone number, and enter a 10 digit phone number.</p>");
$problem = true;
} else {
$_POST['phone_number'];
}
// If there weren't any problems
if (!$problem) {
echo "<p>You are now registered " . ucfirst($first_name) . "! Please check your hooman's email for your Registration Conformation.</p>";
// Send the email
$body = "Thank you, {$_POST['first_name']}, for registering for the FREE 'Your Healthy Dog' class!' We will see you and your hooman soon! We will be contacting you with the date & time of our class. Keep wagging!";
mail($_POST['email'], 'Registration Confirmation', $body, "(email goes here)";
// Clear the posted values
$_POST = [];
}
}
?>
<!-- End PHP script -->
<!-- Start Form -->
<form action="register.php" method="post">
<p><label>Dog's First Name: <br><input type="text" name="first_name" size="20" value="<?php if (isset($_POST['first_name'])) {
print htmlspecialchars($_POST['first_name']);
} ?>" autofocus></label></p>
<p><label>Your Last Name: <br><input type="text" name="last_name" size="20" value="<?php if (isset($_POST['last_name'])) {
print htmlspecialchars($_POST['last_name']);
} ?>"></label></p>
<p><label>Email address: <input type="email" name="email" value="<?php if (isset($_POST['email'])) {
print htmlspecialchars($_POST['email']);
} ?>"></label></p>
<p><label>Dog Breed: <br><input type="text" name="dog_breed" size="50" value="<?php if (isset($_POST['dog_breed'])) {
print htmlspecialchars($_POST['dog_breed']);
} ?>"></label></p>
<p><label>Phone Number (numbers only, and no spaces): <br><input type="text" name="phone_number"
size="10" value="<?php if (isset($_POST['phone_number'])) {
print htmlspecialchars($_POST['phone_number']);
} ?>"></label></p>
<input type="submit" value="Register!">
</form>
<!-- End Form -->
</main>
<footer>
<!-- Links to W3C HTML5 & CSS Validation and your Course Homepage -->
<p id="validation">
<a href="http://validator.w3.org/nu/?doc=https://gentrya698.macombserver.net/itwp2750/project2/register.php"
title="HTML5 Validation - W3C">HTML5 Validation</a> |
<a href="https://jigsaw.w3.org/css-validator/validator?uri=gentrya698.macombserver.net/itwp2750/project2/styles.css"
title="CSS Validation - W3C">CSS Validation</a> |
<a href="../home.htm">Course Homepage</a>
</p>
<p id="shout_out">Form layout CodePen courtesy of <a href="https://codepen.io/dfitzy/pen/VepqMq"
title="Vintage Inspired Contact Form" target="_blank">David Fitas</a><br>
All images are released under the <a href="https://pixabay.com/service/faq/" target="_blank"
title="Stunning free images & royalty free stock">Pixabay License</a>, copyright free.</p>
</footer>
</body>
</html>
I'm working on a basic user management system to study classes.
I've set up a jupitermailuserdb
in PHPMyAdmin from XAMPP. It currently has a single table, users
, which has 4 columns: user_id
, username
, email
, and password
.
Which framework or tool should I use to create the visual interfaces? Like, the basic textboxes for entering new usernames, etc.?
Additionally, how to obscure the password
field? It's currently displayed as plain text but I've seen a few WordPress databases and the sensitive data appears to be a hash rather than plain text. How would I do that?
phpMyAdmin - Error
Error during session start; please check your PHP and/or webserver log file and configure your PHP installation properly. Also ensure that cookies are enabled in your browser.
session_write_close(): write failed: No space left on device (28)
session_write_close(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/sessions)
Bonsoir à tous ,
Je rencontre des problemes concernant le lancement de easyphp .
Au début j’avais un probleme de fichier manquant le msvcr110.dll mais j'ai reinstallé les programmes Microsoft visual c++ 2008 , 2012 ,2013, 2015 -2022 et ce message n'est plus apparut cependant le nouveau problème est que mon database serveur ne se lance pas il tourne mais le bouton reste vert et aucun message d'erreur ne s'affiche.
J’ai installé et désinstallé les programmes Microsoft visual c++ plusieurs fois tout comme easyphp.
Je vous remercie d’avance pour vos réponses !