October 22, 2024
Chicago 12, Melborne City, USA
PHP

PHP sends curl to submit a login request, it receives code 302, and the automatic jump will return Code 411

All tests can be completed in postman, and the Location page after login is displayed correctly. However, when the postman output as php-curl: <?php include('php/simple_html_dom.php'); $username="username"; $password = 'password'; $curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => 'https://somesite.com/', CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 10, CURLOPT_ENCODING => '', CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 10, CURLOPT_CUSTOMREQUEST => 'GET',

Read More
PHP

How to unit test a symfony/console application command?

I use only the symfony/console@7.1 library to create a small cli application. I want to unit test the command as is, yet the the unit test provides no output. This is my unit test setup: class TimrOverviewCommandTest extends TestCase { public function testTimrOverviewCommand() { $input = new ArgvInput(argv: [ "overview", "--csv", "tests/csv/day_report.csv" ]); $buffered =

Read More
PHP

get_query_var returns wrong value

I create a rewrite rule with different params add_rewrite_rule( '^shop/(\b(thanks)\b)/([0-9]+)/([0-9]+)$', 'index.php?pagename=shop&shop_endpoint=$matches[1]&ref=$matches[2]&key=$matches[3]', 'top' ); add_filter('query_vars', function($vars){ $vars[] = 'shop_endpoint'; $vars[] = 'ref'; $vars[] = 'key'; return $vars; }, 10, 1); I have the following url https://www.example.com/shop/thanks/2956789/6212/ If I dump get_query_var('schop_endpoint'); get_query_var('ref'); get_query_var('key'); the output is thanks thanks thanks and not thanks 2956789 6212 I does not

Read More
PHP

Cannot make static method Illuminate\Support\Facades\Http::preventStrayRequests() non static in class Illuminate\Http\Client\PendingRequest

I have error in Laravel Cannot make static method Illuminate\Support\Facades\Http::preventStrayRequests() non static in class Illuminate\Http\Client\PendingRequest use Illuminate\Support\Facades\Http; public function parse(string $productId): void { $this->productId = $productId; $url = self::DETAIL_URL . $productId; $response = Http::get($url); $json = json_decode($response->body(), true); $this->data = $json['data']['products'][0] ?? []; } You need to sign in to view this answers

Read More
PHP

Laravel 11.x Eloquent Way To Get Relation Through Relations (4 Total Tables)

I’m using latest version of Laravel. I’m trying to setup a model method relationship that passes through other intermediary tables. Understanding the table structure below, my goal is retrieve a collection of Students (only) which are enrolled in a course that belongs to a curriculum model. Curriculum->Course->Students Course->Student I’ve come close, as you can see

Read More
PHP

How can I connect to my mysqli database without errors?

// Database connection variables $host = "localhost"; $username = "root"; // $password = ""; // $dbname = "php_pro"; // // no 9 Create a new MySQLi connection $conn = new mysqli("localhost", "root", "", "php_pro"); // Check if the connection was successful if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } The program yields ‘not able

Read More
PHP

Sporadic functionality in Symfony 7 registration method

I have a registration method in my Symfony 7 application which is working for the most part, however certain parts seem like they aren’t being called and logging isn’t working at all. public function register(Request $request): Response { $this->logger->critical('Testing first line of function'); $userRegistrationDTO = new UserRegistrationDTO(); $form = $this->createForm(UserRegistrationType::class, $userRegistrationDTO); $form->handleRequest($request); $this->logger->critical('testing logger before

Read More
PHP

can't open the page, too many redirects occured trying to open my local program

enter image description here Currently im encountering this problem which also affects my preloader for my vectors of java and css, i don’t know what caused this because from my last push from the main to the github all of the functions of my program and even just loading my program is working, but now

Read More
PHP

WooCommerce custom order number prepending product sku

I am building a WooCommerce web-store with different and I want to get different series of order numbers or invoice numbers based on this thread. I need a similar solution. The codes I’ve tried: 1st try add_filter( 'woocommerce_order_number', 'change_woocommerce_order_number' ); function change_woocommerce_order_number( $order_id ) { $order = new WC_Order( $order_id ); foreach ( $order->get_items() as

Read More
PHP

restrict user uploading image by 3 files only

im looking if(empty($id)){ $save = $this->db->query("INSERT INTO posts set $data"); if($save && isset($img)){ $id= $this->db->insert_id; mkdir('assets/uploads/'.$id); for($i = 0 ; $i< count($img);$i++){ list($type, $img[$i]) = explode(';', $img[$i]); list(, $img[$i]) = explode(',', $img[$i]); $img[$i] = str_replace(' ', '+', $img[$i]); $img[$i] = base64_decode($img[$i]); $fname = strtotime(date('Y-m-d H:i'))."_".$imgName[$i]; $upload = file_put_contents('assets/uploads/'.$id.'/'.$fname,$img[$i]); $data = " file_path="".$fname."" "; } }

Read More