PHP

121K

Solutions

33K

Contributors

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.

Share tech news, updates, or what's on your mind.

Sign up to Post

Hi,
I have e PHP (7.1) for cycle that should run through > 80000 loop, but every time it stops at the very same cycle (5884).
Basically this script fetch some content from a remote FTP, and the does lots of INSERT in mysql database.
I would like to troubleshoot this, any suggestion?
thank you very much!
0
After successfully uploading an image using a form, I want to reference the uploaded image using the URL of the site combined with the file name.

I can do it by using this:

<img src="http://nomas.site/assets/img/{{ $film->thumbnail }}">

Obviously, while it's a short term fix, I want to use the asset helper, but I'm stuck in that when I try this:

<img src="{{ asset('assets/img/{{ $film->thumbnail }}') }}"

I'm coming up short.

What am I missing?
0
Hi Experts


Could you point what must to be adjusted at this view's code to avoid the form beeing submited if the modal's textbox is empty?

Accordingly with:


<?

<div class='row'>
    <br/>
    <div class="well well-lg text-center">
        <h1>Fotos</h1>
    </div>
</div>

<input type='hidden' id='pagina' value='1'/>

<div class="container">
    <div class="row">
    
          <!--div class="panel panel-primary"-->
          <div class="panel panel-default">
          
            <div class="panel-body">
                <div class=" col-md-12 col-sm-12"> 
                      <div class='row'>
                      
                         <div class="col-sm-12 col-md-6">
                          <div class="btn-group" role="group">
                            <button type="button" class="btn btn-primary" onclick="Xxxxx.vitrine.minhasfotos();">
                              <i class="fas fa-video" aria-hidden="true"></i> Minhas Fotos
                            </button>
                          </div>
                        </div>
                        
                         <div class="col-sm-12 col-md-3">
                          <div class="btn-group" role="group">
                            <button type="button" class="btn btn-primary" onclick="Xxxxx.vitrine.todasfotos();">
                              <i class="fas fa-video" aria-hidden="true"></i> Todas as Fotos
                            </button>
                          </div>
   

Open in new window

0
I am using PHP to make a call to MSSQL server.
It is returning a field type 'varbinary' that I am using to hold the data on an image

Then I would use the hex field to convert it and display it
$photo= hex2bin(	$photo);
 echo '<div class="img-outer"><img class="img img-responsive img-circle" src="data:image/jpeg;base64,'.base64_encode( $photo ).'"/></div>'; 

Open in new window


The code worked perfectly with PHP 5.6
Now the server has been upgraded to PHP 7.2 and now the binary field is coming back as gibberish and the hexbin is throwing an error that it's not hexdecimals.

What do I need to do to make this work now?
Thank you
0
I have a PHP Web application which we sell on subscription model and I would like to add an authentication option like authenticator to add another layer of security an also that our users can feel that the application is more secure.
I'll appreciate your advise on which authentication tool could be more useful and could be implemented in PHP and please advise if there are some other alternatives to authentication.

Thanks

Luis Rodríguez
0
I have this array .
how can I sort by first name in php (current;y it's sorted by id) ?

 
[1611] => Array
        (
            [first_name] => Daniel
        )

    [1610] => Array
        (
            [first_name] => Batman
        )

    [1609] => Array
        (
            [first_name] => Abraham

        )

Open in new window

0
I have a site I am working on that when you do a search for a post_type, it won't change the title.  I have the following hack but it does not work because it runs before the jQuery library is included.

function searchfilter($query) {
    if ($query->is_search && !is_admin() ) {
        if(isset($_GET['post_type'])) {
            $type = $_GET['post_type'];
                if($type == 'product') {
                    ?>
    <script>
    (function($){
        var term = '<?php the_search_query(); ?>';

        $('.archive-title').text("Your Search for: " + term + "");
        })(jQuery);
    </script> 
    <?php
                }
        }       
    }
return $query;
}
add_filter('pre_get_posts','searchfilter');

Open in new window


You can see what I mean here: https://gardenersstage.wpengine.com/?s=seeds&post_type=product
"Shop Our Store"  Should say "Your Search for: " + term + "" Or do you know how to change the title of the page if the post type is set?
0
I came close to getting the result but didn't get the desired result. can someone please help me
In the first part is my PHP array, the second part is the desired result.
I do have control of creating this array, if you have a better suggestion let me know.
Array
(
    [Home] => Array
        (
            [Dashboard] => Array
                (
                    [url] => index.php
                    [class] => fas fa-list
                    [name] => My Application's
                    [perm] => 10
                    [active] => 1
                )

        )

    [Accounts] => Array
        (
            [My Accounts] => Array
                (
                    [url] => index.php
                    [class] => fas fa-list
                    [name] => My Application's
                    [perm] => 10
                    [active] => 1
                )

            [Achived Accounts] => Array
                (
                    [url] => index.php
                    [class] => fas fa-list
                    [name] => My Application's
                    [perm] => 10
                    [active] => 1
                )

        )

    [Applications] => Array
        (
            [My Applications] => Array
                (
                    [url] => index.php
                    [class] => fas fa-list
                    [name] => My Application's
                    [perm] => 10
                    [active] => 1
                )

            [New 

Open in new window

0
I am sending form data to a 3rd party API but get this error:

HTTP/1.1 415 Cannot process the message because the content type 'application/x-www-form-urlencoded' was not the expected type 'text/xml; charset=utf-8'

So, I am trying to troubleshoot by sending the data via Postman but getting the same error. Not really sure how to resolve this? I have been trying to change the content type to text and xml etc. but still keep getting similar errors.

In the headers I have:

Content-Type : application/xml

Not sure if that needs to change
0
I have a simple question form which inserts the question into a mysql database (all on a local network).
I need the facility to print multiple copies of the question on 2 different printers instantly (or within 30 seconds of the question being entered..

Is there a way of automating this via PHP rather than relying on the client to do this?

Ideally the db will be updated once the printing has been sent.

Any ideas?
0
I'm using a Child theme in my Wordpress site, and I want to override a line in my parent theme's Functions.php file:

If( ! current_theme_supports( 'deactivate_tribe_events_calendar' ) )
{
    // Below was removed to make single events look better:
	require_once( 'config-events-calendar/config.php' );			//compatibility with the Events Calendar plugin
}

Open in new window

I want to comment out the "require_once" line. I tried adding that to my child's Functions.php line:

If( ! current_theme_supports( 'deactivate_tribe_events_calendar' ) )
{
    // Below was removed to make single events look better:
    //	require_once( 'config-events-calendar/config.php' );			//compatibility with the Events Calendar plugin
}

Open in new window

But when the site loaded it ignored that and obviously used the line from the parent theme.

How can I do that without having to worry about updating every time my theme updates?
0
Hello,
We have recently upgraded to php 7.4 for our intranet on windows 10 and we are getting a database not found error. All the files for the database are there and should be in working order. Everything worked fine on 7.3 with Windows 7.The log files do not give any hints as to why the database isn't being found. Does anyone know of anything that would have changed between versions?

Thanks
0
How can I calculate values of fields and update the db without leaving or refreshing the PHP page?

Boy do I need help! I've been struggling with this for far too long.
The frustrating thing about it is that I know there's a simple solution because I've done it before -- but I can't find my old code.
So I'm reaching out to guys who know this stuff much better than I do.

I'm merely trying to subtract a value of one field from the value of another field, then inserting the results into a third field, and updating the database -- without leaving or refreshing the page.

Below is a simple example of what it is I'm trying to accomplish.
Any help is greatly appreciated.
Sas

<INPUT type=text readonly='readonly' name='[b]AmountBILLED[/b]' value='[b]$AmountBILLED[/b]'> 
[i]NOTE: The value of field '[b]AmountBILLED[/b]' is harvested from a database [/i]

<INPUT type=text name='[b]AmountPAID[/b]' > 
[i]  The value of field '[b]AmountPAID[/b]' is entered by the end user [/i]

[i]  On Focus or Click of a (CALCULATE button) do the math - subtract the value entered in '[b]AmountPAID[/b]' from the value of '[b]AmountBILLED[/b]' and
 insert that value into the '[b]AmountDUE[/b]' field automatically, and UPDATE the db [/i]

<INPUT type=text readonly='readonly' name='[b]AmountDUE[/b]'  value='[b]$AmountDUE[/b]'>
[i] Another option to updating the value of [b]AmountDUE[/b] is to merely do so as a variable that is not in an <INPUT field. [/i]
[i] Thank the Expert who made my 

Open in new window

0
I have installed a basic google analytics plugin and for the most part it works. It tracks all the pages and taxonomies but not the custom post type. So, once you drill down on the actual website to:

https://example.com/product/some-category/some-item

In google analytics it only goes as far as:

https://example.com/product/some-category/

leaving off the item.

When I view the source of the custom post type product item page, I can see that the tracking code is there.

Does anyone know why this might be happening?

Post type:

register_post_type('product', array(
'supports'      => array('title', 'editor', 'thumbnail', 'excerpt'),
'rewrite'       => array('slug' => 'product'),
'has_archive'   => true,
'public'        => true,
'labels'        => array(
        'name'         => 'Products',
        'add_new_item' => 'Add New Product',
        'edit_item'    => 'Edit Product', 
        'all_items'    => 'All Products',
),
'menu_icon'     => 'dashicons-cart'
));

Open in new window



Plugin used:

https://wordpress.org/plugins/ga-google-analytics/
0
Hello,

I am looking for the equivalent in VB.NET (or in C #) of the following PHP code

$params = array(
  'http'=>array(
    'method'=>"POST",
    'header'=>"content-encoding: amz-1.0 ....Signature=1c1b2f3c38bac12904cf84",
    'content' =>"example")
);
$stream = stream_context_create ( $params );

$fp = @fopen ( 'http://www.example.com, 'rb', false, $stream );

$response = @stream_get_contents ( $fp );
0
I'm working on a Laravel project and I'm attempting to "add" and "commit" a number of files simultaneously and I've run into something I've never seen before.

Rather than plow ahead with solutions that seem intuitive on the web, I wanted to run this by some folks who I'm sure have seen this.

When I go to do a

"git commit -m "my message"

I get this error:

[code]error: invalid object 100644 6a247fefd088bae6baae483aa27872517393f5fe for 'app/Http/Controllers/Auth/ForgotPasswordController.php'
error: invalid object 100644 6a247fefd088bae6baae483aa27872517393f5fe for 'app/Http/Controllers/Auth/ForgotPasswordController.php'
error: Error building trees[/code\

When I went out to Google in an attempt to remedy the situation, I saw this:

https://medium.com/@panjeh/git-error-invalid-object-error-building-trees-44b582769457 (see also https://git-scm.com/book/en/v2/Git-Internals-Git-Objects)

Sha-1 looks as though it's just a way of telling GIT to overlook what would otherwise be a snag. Is that right?

Then I found this: https://stackoverflow.com/questions/17628305/windows-git-warning-lf-will-be-replaced-by-crlf-is-that-warning-tail-backwar

From what I can gather, depending on your OS, Windows is going to interpret LF differently than a Linux system, hence GIT looks at LF and wants to replace it with CRLF.

Right?

I'm getting to share this with another developer and I want to make sure that I'm not just blowing through something I need to be …
0
Hello!
I have a form on my web-site where one can attach his (her) photo by the end of it and then click SEND button below. If one uses a regular PC (say, notebook) then everything if fine. But, unfortunately, nowadays most people use smartphones and then there's a problem. Housewives have no idea what is a file size and they have no clue how to lessen it in a Photo Editor app. Not like they even care...  They just buy new phones with 12-15 megapixel built-in cameras and shoot. If one uses his (her) Android smartphone to send that online form and attaches a photo of, say, 3,5 MB in size, then everything is okay. But if a photo, say, 5,2 MB then there's an Android error message (with an Android "robot" in it) ERR_FAIL or something like that. I contacted my mobile career and they said that they don't have any particular limitation on file size to be sent. Also the phone (it's Philips) reps told me that the phone itself doesn't have such limits. Then it must be an Android issue or... of mobile Android browsers. As per iOS (Apple)... I frankly don't know... I personally don't have such a phone and not many people in our country use them (probably too expensive???)...
My phone is Philips S257 (if it makes any difference). It operates on Android 7.0 But I think it doesn't matter, 'cos other people with other phones had the same issue. It's just for me it's easier to check it on my own device.
Any ideas?
0
Greetings!  We run an open source software called OJS (Open Journal Systems) in XAMPP on Windows 2016 server with PHP 7.2.11, and Apache 2.4.35. The site is supposed to show me the available plugins when I go to the Plugin Gallery page, but the page says "No items".  OJS folks explain that our server doesn't fetch the plugin list from their server. They point to that function in the /plugins/PluginGalleryDAO.inc.php as a ossible culprit:

private function _getDocument() {
    $doc = new DOMDocument('1.0');
    $gallery = FileWrapper::wrapper(PLUGIN_GALLERY_XML_URL);
    $doc->loadXML($gallery->contents());
    return $doc;

According to them, this is the function that fetches the plugin list from the PKP server (https://pkp.sfu.ca/ojs/xml/plugins.xml, defined at the head of that file). They suspect I’ll find that $gallery->contents() is failing to return the contents of that XML file.  The suggestion is to try to use error_log to log variables/results from within PHP code, but I am no sure how to do that.  Could someone guide me?
0
I have purchased the Events Calendar Pro WordPresss plugin. I am trying to make the countdown timer look better but I am new to php and apparently I suck at it.

I have been trying to edit the countdown-widget.php file in an effort to make it look better because the default one is terrible. I want it to look more modern.

This is what i have tried:
<table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="#657b86">
   <tr>
     <td width="50%"><p align="center"><img border="0" width="200" height="148" src="<?php echo $img; ?>" ></td>
   
     <td align="center" width="50%"><font size="30px"><div class="tribe-countdown-days tribe-countdown-number">DD</font><br />
            <span class="tribe-countdown-under"><?php esc_html_e( 'days', 'tribe-events-calendar-pro' ); ?></span>
      </div>
      <div class="tribe-countdown-colon">:</div>
      <div class="tribe-countdown-hours tribe-countdown-number">HH<br />
            <span class="tribe-countdown-under"><?php esc_html_e( 'hours', 'tribe-events-calendar-pro' ); ?></span>
      </div>
      <div class="tribe-countdown-colon">:</div>
      <div class="tribe-countdown-minutes tribe-countdown-number">MM<br />
            <span class="tribe-countdown-under"><?php esc_html_e( 'min', 'tribe-events-calendar-pro' ); ?></span>
      </div>
      <?php if ( $show_seconds ) : ?>
            <div class="tribe-countdown-colon">:</div>
            <div class="tribe-countdown-seconds tribe-countdown-number tribe-countdown-right">SS<br />
                  <span class="tribe-countdown-under"><?php …
0
We've built a web tool that collects health data via a set of questions that can be embedded as an iFrame in various websites that wish to have this data collected.

This all seems to work fine and the iFrame loads for all customers' sites. However, sometimes certain browsers will fail to load the iFrame - a user will see a blank space where our content/questions should load.

The occasional glitch hasn't been a huge worry although we think this is happening more regularly now. This suggests it might be something in newer broswer releases that is tightening security. It has been happening more often on handheld devices as well as laptops etc.

At the same time we've noticed other iFrame offered services still continue to work (such as Stripe credit card pop-ups) on these same devices/laptops which means they are probalby doing something different.

Any ideas what we might do?

Thanks in advance
Iain
0
My site is built in WordPress with WooCommerce and is a wholesale site and so all the products add to cart is disabled until the user is logs in. But due to caching of browser, even after the user is logged in, the add to cart is not being enabled, the logged in user has to refresh the page multiple times to see the add to cart button.

Below is the code I am using to disable and enable the add to cart button

* display add to cart only to wholesale group */
if(is_user_logged_in() )
{
    $current_user = wp_get_current_user();
    foreach ( $current_user->roles as $role )
    {
        if($role != "Wholesale Buyer" || $role != "Customer" || $role != "Admin")
        {
            // If user role is Wholesale Buyer or Customer or Admin, Add to Cart button and Price will display on both Single and Shop/Category Pages
        }
    }
}
else
{
    pc_woo_remove_add_to_cart_and_price();
}


function pc_woo_remove_add_to_cart_and_price()
{
    // Remove Add to cart from Single Product Page
    remove_action( 'woocommerce_simple_add_to_cart', 'woocommerce_simple_add_to_cart', 30 );
    remove_action( 'woocommerce_grouped_add_to_cart', 'woocommerce_grouped_add_to_cart', 30 );
    remove_action( 'woocommerce_variable_add_to_cart', 'woocommerce_variable_add_to_cart', 30 );
    remove_action( 'woocommerce_external_add_to_cart', 'woocommerce_external_add_to_cart', 30 );
    remove_action( 'woocommerce_single_variation', 'woocommerce_single_variation_add_to_cart_button', 20 );
 

Open in new window

0
Hi guys,

Can you help me out on how i fix the formatting on this page here where i could have 4 rows of 3 https://vendorfinance.ie/our-products/

i have attached the code here

<?php

/**
* Template Name: Products template
*/

get_header(); 
?>
<script>
$(document).ready(function(){
$(".pou6").click(function(event) {
	event.preventDefault();
    $('html, body').animate({
        scrollTop: $(".makeitu").offset().top
    }, 2000);
});	
});

</script>
<style>.header-outer{border-bottom: 2px solid #484A54;}
</style>
<div class="por1" style="position: relative;">
	<img src="<?php echo site_url(); ?>/wp-content/uploads/2019/11/product-banner.jpg" class="img-responsive pou3" />
	<div class="container pou4">
		<div class="row">
			<div class="col-md-12">
				<p class="pou1">OUR FINANCIAL PRODUCTS</p>
				<p class="pou2">At Vendor Finance, we are your one-stop-shop for all your financial requirements.<br>Check out some of our finance products below and if you have any questions,<br>feel free to contact our team. </p>
				<p class="pou5"><a href="" class="pou6">DISCOVER PRODUCTS</a> <a href="https://vendorfinance.ie/contact/" class="pou7">GET IN TOUCH</a></p>
			</div>
		</div>
	</div>
</div>
<!-- calculator -->
<div class="container makeitu">
	<div class="row">
		<div class="col-md-4 pou-dist">
			<div class="pou8" style="background:url(https://vendorfinance.ie/wp-content/uploads/2019/11/a11.jpg) no-repeat;background-size: cover;"></div>
			<div class="pou9">
				<p 

Open in new window

0
I have a website that used to work but ever since I suspect an upgrade from the provider it has stopped. This website is pretty simple, but I had inserted PHP to run inside HTML. It works when I run it on a local machine with XAMPP installed on.  But when I add the similar settings to the website it either just shows the PHP code or as soon as I open the website it downloads the HTML page that I refer to.

All I have done on the website side is adjust the HTACCESS to include the below (have tried different ones and they either end up downloading the HTML or just displaying the PHP Code).

#AddType application/x-httpd-php .htm
#AddType application/x-httpd-php .html
#AddType text/html .html

#AddType application/x-httpd-php .php .html
#AddHandler x-httpd-php56 .php .html
AddHandler application/x-httpd-php .php .html .htm

With that simple insertion before on the website it worked, now it has stopped.

I checked what PHP version and it said 5.6,, when it works on XAMPP that is running 5.5.1.

Can anyone give me any guidance, checks or fixes.

Highly appreciated

Cheers

Matthew
0
Hi:

I am unable to make my AWS EC2 instance connect to my RDS MySQL DB through SSL using PHP.

AWS EC2 Linux 2, Apache 2.4.39, PHP 7.3.10, MySQL 5.7.26

In order for my application that resides in EC2 to have a secure connection in transit, it must utilize SSL/TLS. My understanding that given my PHP/MySQL application, I need to perform the code below. In order not to affect my DB, I have set up a test DB in the same DB_server. The new user is called new-user with its own password. The bundled PEM file is rds-combined-ca-bundle.pem.

From various sources I put together the following code.

In AWS-test-ssl-script.php ..
34 require_once('AWS-test-config.php');
35 require(MYSQLI);

44 $sel = "CREATE USER IF NOT EXISTS 'new-user'@'%' IDENTIFIED BY 'password' REQUIRE SSL";
45 $sel_qry = mysqli_query($dbc, $sel);
46 mysqli_close($sel_qry);

// Simple test query ..

Open in new window

In AWS-test-config.php ..
define ('MYSQLI', 'AWS-test-connect.php');

Open in new window

In AWS-test-connect.php ..
12 $dbc=mysqli_init();
13 mysqli_ssl_set($dbc, NULL, "/dir/rds-combined-ca-bundle.pem", NULL, NULL, NULL);
14 mysqli_real_connect($dbc,"DB_server","new-user","password");

16 $res = mysqli_query($dbc, 'SHOW STATUS like "Ssl_cipher"');
17 print_r(mysqli_fetch_row($res));
18 mysqli_close($dbc);

Open in new window

Output ..
Warning: mysqli_real_connect(): Unable to set private key file `rds-combined-ca-bundle.pem' in AWS-test-connect.php on line 14
Warning: mysqli_real_connect(): Cannot 

Open in new window

0
Hi, I'm using Nylas for mail syncing and have a webhook setup in Nylas and receiving it in my Laravel application.

From Nylas docs:
"The body of the POST request is encoded as a UTF-8 JSON object with the following attributes:
Attribute        Type          Description
deltas            array          An array consisting of a single delta object."

So it seems to be a json object that contains an array??

The incoming webhook looks like this:
{
"deltas": [{
"date": 1577127539,
 "object": "message", 
"type": "message.created", 
"object_data": {
"namespace_id": "93d6z2qmxm050zh2znnpxxxxx", 
"account_id": "93d6z2qmxm050zh2znnpxxxxx",
 "object": "message", 
"attributes": {
"thread_id": "6ejmdhd2p0iyhscfac21yyyyy", 
"received_date": 1577127517
}, 
"id": "ioe47mlrjm592gbrc01bbbbb", 
"metadata": null
}
}]
}

Open in new window


So my question is: how do I receive that in Laravel and get at the values?

Tried below but fails unsurprisingly (I think its because I'm receiving an object that contains an array?)

$results                   = $request->all();
$json                         = json_decode($results);
   
$Type                        = $json['deltas'][0]['type'];
$Thread                  = $json['deltas'][0]['object_data']['thread_id'];
$AccountId                  = $json['deltas'][0]['object_data']['account_id'];
$MessageDate            = $json['deltas'][0]['date'];
$MessageId                  = $json['deltas'][0]['object_data']['id'];

Thanks for any help in advance.
0

PHP

121K

Solutions

33K

Contributors

PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.