#StackBounty: #php #url Convert URL into one standard format

Bounty: 50

Here are a few URLs:


As you can see, they all lead to the exact same page but the URL format is different. Here is two other basic examples:


Both are the same.

I want to convert the URL into one standard format so that when I store the URL in the database, I can easily check whether if the URL string already exists in the database.

Because of the various ways of how the URL can be formatted, this can be puzzling.

What’s the definitive approach to converting URL into one standard format? Maybe parse_url() route…?


As outlined in the comments, there is no definitive solution to this, but the aim is to get as close as possible with what we have without “retrieving” the page. Please read comments before posting an answer to this bounty.

Get this bounty!!!

#StackBounty: #php #sql-server #codeigniter #pdo #sqlsrv PHP MSSQL num_rows() not working with sqlsrv driver in Codeigniter

Bounty: 50

I’m getting the following error on a simple query that’s supposed to return a number of rows:

Type: Error

Message: Call to a member function num_rows() on boolean


Line Number: 1428

I’m using Codeigniter 3.1.9. I recently started using PHP7.2 and also sqlsrv driver to connect to a MSSQL database.

In some other post, someone mentioned that scrollable should be set to an option different than SQLSRV_CURSOR_FORWARD so I dump the value of $this->scrollable in sqlsrv_driver.php and found out that its value is buffered

     * Execute the query
     * @param   string  $sql    an SQL query
     * @return  resource
    protected function _execute($sql)
        echo $this->scrollable; die();
        return ($this->scrollable === FALSE OR $this->is_write_type($sql))
            ? sqlsrv_query($this->conn_id, $sql)
            : sqlsrv_query($this->conn_id, $sql, NULL, array('Scrollable' => $this->scrollable));

Not quite sure why it’s failing. Any other queries that don’t include num_rows() are fine so far.

Get this bounty!!!

#StackBounty: #php #laravel Why the custom rule is not working? (allow user to select only the quantity for one registration type)

Bounty: 50

I have a select menu for the user to select the quantities of each
registration type that he wants.

<form method="post" action="{{route('conferences.storeQuantities', 
['id' => $conference->id, 'slug' => $conference->slug])}}">
    <ul class="list-group">
        {{ csrf_field() }}
        @foreach($registration_types as $rtype)
            <select id="rtype_{{ $rtype->id }}" 
                    data-price="{{ $rtype->price }}"
                    name="rtypes[{{ $rtype->name }}]">
                <option value="0">0</option>
                @for ($i = $rtype->min_participants; $i <= $rtype-> max_participants; $i++)
                    <option value="{{ $i }}">{{ $i }}</option>

But there are some validation rules for this field that are not working properly. Basically there are 4 things that should be validated:

  • the field is required
  • the quantity introduced by the user should be between min_participants and max_participants (min_participants and max_participants are columns in the registration_types table and means the minimum and maximum quantity that a user can select for a specific registration)
  • the user needs to at least select the quantity for a registration type available for the confernece and for the other registration types should be allowed to select “0”
  • but the user can´t introduce the quantity “0” for all registration types available in the conference

Issue: But its not working properly, if the user selects for example the quantity “1” for registration type “general” and for the registration type “plus” “0” it appears the validation error defined in the message() of the RegistrationTypeQuantity rule. But the user should be able to select only the quantity for 1 registration type.

Do you know how to solve that?

The RegistrationTypeQuantity rule that is used in the storeQuantities(), basically the quantities are sum and then is checked if the quantity is greater than 0:

 public function passes($attribute, $value)

        $quantity = 0;

        foreach($value as $key=>$v) {

            if ( is_null($v)) return false;

            $rtype = RegistrationType::where('name',$key)->first();
            if ( ! $rtype) return false;

            // $rtype was found
            if ( ($v < $rtype->min_participants || $v > $rtype->max_participants) )
                return false;

        // track total quantity selected
        $quantity += (int)$v;

        // make sure there was at least one purchase
        if ($quantity === 0) {
            return false;

        return true;

Method to store the selected quantities by the user for each registration type

 public function storeQuantities(Request $request, $id, $slug = null)
        'rtypes' => ['required', 'array', new RegistrationTypeQuantity],
        if ($validator->fails())
        return redirect()->back()->withErrors($validator, 'quantitiesError');

    $rtypeQuantities = $request->get('rtypes');
    $total = 0;
    $selectedRtypes = [];

    foreach ($rtypeQuantities as $rtypeName => $quantity) {
        if ($quantity) {
            $rtype = RegistrationType::where('name', $rtypeName)->firstOrFail();

            $price = $rtype->price;

            $selectedRtypes[$rtype->name]['quantity'] = $quantity;
            $selectedRtypes[$rtype->name]['price'] = $price;
            $selectedRtypes[$rtype->name]['subtotal'] = $price * $quantity;
            $total += $selectedRtypes[$rtype->name]['subtotal'];
            $selectedRtypes[$rtype->name]['total'] = $total;

            $selectedRtypes[$rtype->name]['questions'] = $rtype->questions;
            $selectedRtypes[$rtype->name]['id'] = $rtype->id;
        Session::put('selectedRtypes', $selectedRtypes);
        Session::put('customQuestions', $selectedRtypes[$rtype->name]['questions']);
        Session::put('total', $total);
    return redirect(route('conferences.registration', ['id' => $id, 'slug' => $slug]));

HTML of the select menu to select the quantities:

Registration Type Quantity Price
  • general
    <select class="custom-select form-control rtype_name" id="rtype_1" data-price="5" name="rtypes[geral]"> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> </select> <span>X 5.00€</span> </li> <li class="list-group-item d-flex align-items-center justify-content-between">
    <select class="custom-select form-control rtype_name" id="rtype_3" data-price="10" name="rtypes[plus]"> <option value=""></option> <option value="1">1</option> <option value="2">2</option> </select> <span>X 10.00€</span> </li> </ul> </form> </div> </div>

Validation rules better explained:

If there are two registration types associated with the conference (general and plus), the registration type “general” has the column “min_participants” as “1” and max_participants as “1”, the the registration type “plus” has the column “min_participants” as “1” and max_participants as “2”.

  • If the user click “Next” in the select menu with quantity “0” for registration type “general” and quantity “0” for the registration type “plus” it should fail because the user needs to select at least the quantity for one registration type, because a registration needs to have some registration type(s) associated

  • If the user click “Next” in the select menu with quantity “2” for registration type “general” and quantity “0” for the registration type “plus” it should fail because “general” has “max_participants” as “1” and the user selected the quantity “2” (introduced 2 in the source code for example since in the select menu 2 should not appear for the registration type general, only should appear values between 1 and 1)

  • If the user click “Next” in the select menu with quantity “1” for registration type “general” and quantity “1” for the registration type “plus” it should pass

  • If the user click “Next” in the select menu with quantity “1” for registration type “general” and quantity “0” for the registration type “plus” it should pass because the user should be allowed do a registration without select quantities for all registration types, because the user might want to only do a registration in the registration type “general” and none in the registration type “plus”. So it should not be mandatory for the user select quantities for all registration types.

Get this bounty!!!

#StackBounty: #php #posts #customization #pingbacks Remove option to allow trackbacks/pingbacks from post page options

Bounty: 50

I’m trying to disable all functionality related to pingbacks/trackbacks in WordPress and so far I have this:

add_action( 'pre_ping', 'disable_pingback' );

function disable_pingback( &$links ) {
    foreach ( $links as $l => $link ) {
        if ( 0 === strpos( $link, get_option( 'home' ) ) ) {
            unset( $links[ $l ] );

However when I open up the page options and enable discussion, I still see this:

enter image description here

I found this answer (method 2), but it is over 5 years old now and I wasn’t sure if totally replacing the whole section was the best way to do things compatibility wise, so I am asking again…

Is there a cleaner way to accomplish this?

Get this bounty!!!

#StackBounty: #php #mongodb #database-administration MongoDB connecting over SSL: What am I doing wrong?

Bounty: 50

Overview: I have an application server running PHP 7, connecting to a separate database server running MongoDB 3.6.x using the MongoDB PHP userland library. I have firewall rules preventing access to the MongoDB server from all sources except the local and private interfaces (i.e. disallowing public IP access).

Connections via PHP look something like this:

$context_information = array(
    "ssl" => array(
        "allow_self_signed" => false,
        "verify_peer"       => true,
        "verify_peer_name"  => true,
        "verify_expiry"     => true,
        "cafile"            => "/path/to/ca_bundle"

$context = stream_context_create($context_information);
$connection = new MongoDBClient(
    array('context'=> $context)

My MongoDB configuration looks something like this:

  port: 27017
    mode: requireSSL
    PEMKeyFile: /path/to/my_ca_signed_cert
    CAFile: /path/to/my_ca_bundle

my_ca_signed_cert is a .pem file generated using my openssl-generated RSA private key, as well as the CA-provided .crt file, in the manner described in the MongoDB manual, e.g. cat mongodb.key mongodb.crt > mongodb.pem. my_ca_bundle is the .ca-bundle provided to me by the CA.

Additionally, the ca_bundle described in the PHP context is the same .ca-bundle file as in the MongoDB config.

Problem: I continue to receive the following error:

[23-Jul-2018 16:33:33 America/Los_Angeles] PHP Fatal error: Uncaught MongoDBDriverExceptionConnectionTimeoutException: No suitable servers found (serverSelectionTryOnce set): [TLS handshake failed: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed calling ismaster on. . .

This issue persists even if I comment out the CAFile line for the MongoDB config. Also of note is that I can connect successfully when setting allow_self_signed to true if CAFile is commented out, but not when it’s left uncommented.

Finally, when attempting to connect via the MongoDB shell, I get the following error:

2018-07-23T23:37:02.992+0000 E NETWORK [thread1] SSL peer certificate validation failed: unable to get issuer certificate

2018-07-23T23:37:02.992+0000 E QUERY [thread1] Error: socket exception [CONNECT_ERROR] for SSL peer certificate validation failed: unable to get issuer certificate :



exception: connect failed

Expected Behavior: I don’t want to use client certificate authentication for connecting to the database. All I want at present is for traffic to be encrypted. This means being able to connect to the database without allowing self-signed certificates.


  1. I have a cert set up successfully on the application server for HTTPS connectivity. Additionally, when testing the cert referenced in this question itself, I’ve successfully run verification on the files using openssl verify -CAfile /path/to/my_ca_bundle /path/to/my_ca_signed_cert.

  2. Everything in my application code works when SSL is disabled or when enabled while allowing self-signed certs.

The documentation on all of this is incredibly vague on a number of points, so I’m not sure where my configuration is going wrong. What should I be looking into to resolve this problem?

Get this bounty!!!

#StackBounty: #php #mysql #laravel #homebrew #artisan-migrate Laravel Migration stalls and doesnt do anythign

Bounty: 50

Just went through all the steps listed on the Laravel site to install and get up and running for MacOS HighSierra. I currently have composer, Homebrew, valet, PHP 7.2.8, mySQL version 8.0.11 and Laravel 5.6.28 installed. I can create a new project by doing the Laravel new blog command and not have any problems. Also when I go to my browser I can see current project I just created or am working on. I can run the valet list command and so I know its running/working. I also can create a migration and have it show up in my project as well by running the php artisan make:migration test_test_test.

My PATH also has ~/.composer/vendor/bin in it as well.

my .env file look like such









I run the php artisan migrate -vvv command and it runs and stalls/hangs up with no output. I have to ctl-c to get out of it. tried the -v /-vv as well, did the same thing.

I created a database named blog and even add a table test manually to make sure that the database was working/running.


Went a head and uninstall mySql and reinstall it. I was able to get the php artisan migrate -v command to run and am getting this error.

now I’m getting this error.

MacBook-Pro:anything computername$ php artisan migrate -v

PDOException  : SQLSTATE[HY000] [2006] MySQL server has gone away

at /Users/computername/Sites/anything/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68
64|         if (class_exists(PDOConnection::class) && ! $this->isPersistentConnection($options)) {
65|             return new PDOConnection($dsn, $username, $password, $options);
66|         }
> 68|         return new PDO($dsn, $username, $password, $options);
69|     }
71|     /**
72|      * Determine if the connection is persistent.

Exception trace:

Created a router and view that connects to a table that I creates to see if I would be able to access the database variables and print them out. On return I got this error.

Exception message: PDO::__construct(): Unexpected server respose while doing caching_sha2 auth: 109

Get this bounty!!!

#StackBounty: #php #customization #jquery Removing jQuery migrate and working with dependencies

Bounty: 50

I have jQuery setup in my enqueue scripts section as a dependency, such as:

wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'scripts', get_template_directory_uri() . '/js/scripts.min.js', array( 'jquery' ) );

Now, I want to remove jquery-migrate, but keep jQuery itself obviously, so I found this answer stating to do it like this:

add_filter( 'wp_default_scripts', 'remove_jquery_migrate' );

function remove_jquery_migrate( &$scripts){
        $scripts->remove( 'jquery');
        $scripts->add( 'jquery', false, array( 'jquery-core' ), '1.2.1' );

Firstly, I thought we had removed jQuery migrate here, so not sure what the need of adding the latest version of it is with the comment:

1.2.1 = latest version of jquery-migrate

Secondly, with the way I set my enqueue scripts up, how does that affect the dependencies since I have now removed jQuery and added jquery-core?

Is there a better way to handle this?

Get this bounty!!!

#StackBounty: #php #laravel-5.3 paginate() throws error while using having() while get() shows the results

Bounty: 100


if ($request->going){
    if($request->lattitude && $request->longitude){
        $CurrentIplat = $request->lattitude;
        $CurrentIplon = $request->longitude;
        $ads1 = DB::table('ads')
        ->leftJoin('categories', 'ads.category_id', '=', 'categories.id')
            DB::raw("( 6371 * acos( cos( radians('{$CurrentIplat}') ) * cos( radians( ads.Latitude ) ) * cos( radians( ads.Longtitute ) - radians({$CurrentIplon}) ) + sin( radians({$CurrentIplat}) ) * sin( radians( ads.Latitude ) ) ) ) AS distance")

Gives proper output.

While using paginate()

if ($request->going){
    if($request->lattitude && $request->longitude){
        $CurrentIplat = $request->lattitude;
        $CurrentIplon = $request->longitude;
        $ads1 = DB::table('ads')
        ->leftJoin('categories', 'ads.category_id', '=', 'categories.id')
            DB::raw("( 6371 * acos( cos( radians('{$CurrentIplat}') ) * cos( radians( ads.Latitude ) ) * cos( radians( ads.Longtitute ) - radians({$CurrentIplon}) ) + sin( radians({$CurrentIplat}) ) * sin( radians( ads.Latitude ) ) ) ) AS distance")

It throws

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'distance' in 'having clause' (SQL: select count(*) as aggregate from `ads` left join `categories` on `ads`.`category_id` = `categories`.`id` where `ads`.`domain` = nz group by `ads`.`id` having `distance` < 5000)

Get this bounty!!!

#StackBounty: #php #apache-2.4 #configuration #httpd.conf Apache with PHP running CGI mode: The php executable processes itself, what d…

Bounty: 50

I’m trying to install a pre-Iraq-Surge 4.4.9 PHP in a modern Apache 2.4.6 and want to run it in CGI mode.

The current configuration is as follows:

The PHP executable is /usr/local/php-4.4.9/bin/php

A test file exists in $documentroot/phphere/index.php of the virtual server, it contains:


If I execute the index.php using php, all is hunky dory.


/usr/local/php-4.4.9/bin/php $documentroot/phphere/index.php | less


X-Powered-By: PHP/4.4.9
Content-type: text/html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<style type="text/css">
body {background-color: #ffffff; color: #000000;}
body, td, th, h1, h2 {font-family: sans-serif;}
pre {margin: 0px; font-family: monospace;}
a:link {color: #000099; text-decoration: none; background-color: #



However, calling index.php via a web client results in this:

Warning: Unexpected character in input: '' (ASCII=1) state=1 in /usr/local/php-4.4.9/bin/php on line 277

Warning: Unexpected character in input: '' (ASCII=15) state=1 in /usr/local/php-4.4.9/bin/php on line 277

Parse error: syntax error, unexpected T_STRING in /usr/local/php-4.4.9/bin/php on line 277

which is exactly the output that one gets if one processes the php executable with itself, i.e. the output of

/usr/local/php-4.4.9/bin/php /usr/local/php-4.4.9/bin/php

(less any headers additionally generated).

Ok, so there is some problem in the Apache setup. But what?

The following is configured:

AddType application/x-httpd-php        .php
AddType application/x-httpd-php-source .phps

ScriptAlias /outsidephp             /usr/local/php-4.4.9/bin
Action      application/x-httpd-php /outsidephp/php

If I understand correctly, AddType tags any file ending in .php with MIME type application/x-httpd-php.

If PHP shall be run via CGI conventions, then the executable to run whenever a file with the MIME type application/x-httpd-php is requested is indicated with Action. The ScriptAlias gives an URL-path to the directory in which the php executable can be found. (This syntax sounds awkward though, why not have a single command for that?)

Additionally, the option ExecCGI has been set in the directory containing index.php and the SELinux contexts on that filesystem tree are marked with httpd_sys_script_exec_t.

Note that there is absolutely no

AddHandler cgi-script .php

in the configuration because THAT make Apache try to execute files ending in .php directly as scripts, which predictably fails with Error 500:

Error message:
End of script output before headers: index.php 

What’s wrong exactly?

How do I make Apache run

php index.php

instead of

php php

(i.e. quite probably php php index.php)

Get this bounty!!!

#StackBounty: #php #mysql #wordpress How to change WP mysql user/pass from localhost to server?

Bounty: 50

I just created WP site on my localhost machine and I am about to upload it to production server. Both environments run on the same OS with same libraries and php versions, but the password I set up for my local mysql install is different from the production server. So, I was thinking about uploading the entire WP file and once in the prod, I could alter the wp-config.php and changing the db, but this seems unmanageable in the long term if I have to pull the code to local again or migrate to another server …

so, my question is how is this done?

Get this bounty!!!