We help IT Professionals succeed at work.

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.

Good day Experts,

Need help with turn server and web rpc.. we are getting "ICE failed, add a TURN server and see about:webrtc for more details" and we trying to get our video chat application to work properly.  At moment it only works if i am on the same ISP with a user..if users are on different isps..the voice and video does not work.  We are running tests using this kink https://www.teledoctor.co.zm/livesmart/client.html

When it works we are on same service provider, but voice video stops on different..we are not experts on this and need help to get work across service providers for our application.  Is there a site where one can test a TURN/STUN server setup?

Kind regards
0
First time posting. I have a dropdown with select options listed A through Z...

<select style="width:375px; text-align: left" id="alpha" onchange="fetch_select(this.value);">
<option value="" disabled selected>First Letter</option>
<option value="#">"0-9"</option>
<option value="A">"A"</option>
<option value="B">"B"</option>

<select id="operator" name='operator'>
			<option value="0">- Select Operator -</option>
		</select>
<select id="wnames">
	   <option value="0">- Select Well Name -</option>
	</select>

Open in new window


I also have two dependent dropdowns  that will return their values after the selection of the letter. Onchange of "apha", I need the value to pass to php via ajax, execute two sql queries simultaneously (not cascading), and return the data in json in the two dropdowns, "operator" and "wnames". I don't know how to execute the two sql statements with the one ajax variable and return the two sets of rows.       
Here is my ajax:
//Ajax to fetch operators once alpha chosen
		 function fetch_select(val){
        //var alpha = $(this).val();

        $.ajax({
			type: 'post',
            url: 'alphaScript53.php',
			dataType: 'json',
            data: {op_option:val},
            success:function(response){

                var op_len = response.length;

                $("#operator").empty();
                for( var i = 0; i<op_len; i++){
                    //var id = response[i]['Rig_ID'];
                    var op_name = response[i]['Operator'];
     

Open in new window

0
How do I add a "sign-up" form for my website? I would want a form for the user to fill-in, then the information goes to a database, I suppose. THEN a Thank You notice. I believe this has to be done in javascript.
0
I have set the $type variable at the beginning of PHP code but it doesn't restore correct in my php. Any idea ?

  <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio2" value="Student" "($type=='Student')?'checked':''">


echo
<<<HTML
<form method="POST" action="{$_SERVER['PHP_SELF']}">
<div class="container">
<br/>
<b>Please fill in the following details:</b>
<br/><br/>
Ticket Type: <br/>
<div class="form-check form-check-inline">
  <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio1" value="Regular" ($type=='Regular')?'checked':''>
  <label class="form-check-label" for="inlineRadio1">Regular</label>
</div>
<div class="form-check form-check-inline">
  <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio2" value="Student" "($type=='Student')?'checked':''">
  <label class="form-check-label" for="inlineRadio2">Student</label>
</div>
<div class="form-check form-check-inline">
  <input class="form-check-input" type="radio" name="inlineRadioOptions" id="inlineRadio3" value="Retire" "($type=='Retire')?'checked':''">
  <label class="form-check-label" for="inlineRadio3">Retire</label>
</div>
<br/><br/>
<input class="form-control col-lg-6" type="int " id="id" name="id" placeholder="Student ID" value="$id" required="" ><br/>

<input class="form-control col-lg-6" type="text" placeholder="First Name" name="fname" value="$fname" required="" ><br/>

<input …
0
Hi,

This is related to https://www.experts-exchange.com/questions/29173852/phpmailer-mailbox-unavailable.html

I’m testing sending out automated emails from http://selfregistration.iwscc.ca/email_test/index.php but not all are going through. For example, when I send to aleks@iwscc.ca I get “..mailbox unavailable or not local…”.

Please ignore “email sent” in this instance, because I quickly wrote the script without any error testing. However, it is sending to the following

aleks@aces-project.com (hosted by Microsoft, also mailbox is not local, but working)

apdcompany@gmail.ca (hosted by Google, not local and working)

One thing that I found strange when receiving the credentials for aleks@iwscc.ca as user is that said that if I want to encrypt emails, I need to purchase SSL. I know usually the SSL is for the server side, not client side. I am thinking that maybe that the iwscc.ca is some type of a budget server, but I cannot see how this relates to my script, which is at another server, and it should come down to sending a regular email. Manually, you are  able to email aleks@iwscc.ca.

What could it be?
0
Hello,

Please follow this link and see my category slideshow

http://paula.darkstarmedia.net/category/dance/

I have edited the archive.php page in wordpress to display the most recent  posts featured images in a slideshow, in the category page you are on.

The images are working perfectly, the problem is I am trying to display the title below the image, but as you can see it is grabbing 2 random titles and overlapping them, on top of that the 2 aren't connected to the image.

This is my code

<?php
$category = get_the_category(); 



if( ($category[0]->cat_ID  == 7 && is_category() ) || 
  ($category[0]->cat_ID  == 4  && is_category() ) || 
  ($category[0]->cat_ID  == 1101 &&  is_category() )|| 
	 ($category[0]->cat_ID  == 5  && is_category() ) || 
  ($category[0]->cat_ID  == 3 &&  is_category() )   ) {

?>
<div id="myCarousel" class="carousel slide" data-ride="carousel" >

<!-- Wrapper for slides -->

<div class="carousel-inner">

<?php
$write_active = "active"; 
$args = array(  'posts_per_page' => 5, 'orderby' => 'post_date', 'cat'=> $category[0]->cat_ID  );
$loop = new WP_Query( $args );

while ( $loop->have_posts() ) : $loop->the_post();

echo '<div class="carousel-item '.$write_active.'  " >';
$write_active = ""; 
	
	if (has_post_thumbnail()):
           the_post_thumbnail('default-thumbnail');
      else:
     		echo '<img src="'.$default_thumbnail.'" alt="'.the_title().'" />';
	 endif; 
echo '</div>';


echo '<div class="carousel-caption">';
	echo 

Open in new window

0
Hi Experts,

How can I resize an image dynamically based on their original width or height, without distorting them?

Let me elaborate...

The images are logos that are uploaded by users, so their dimensions are unknown. Some squares, some vertical rectangles, others horizontal. In other words there are 3 possible shapes.

I'm only in the planning phase for this, but i'll have a container (div) for these images, with a fixed size, let's say 190 x 60px.

So based on the 3 shapes and on the known 190 x 60 container, I'd want to end up with the following if the shape is

  • Square
  • , then the display size would be
  • 60 x 60

  • Horizontal
  • , then the display size would be
  • 190 x calc

  • Vertical
  • , then the display size would be
  • calc x 60

In each scenario, the img would remain its original size if it is less than 190x60 I think

Now, I know calc would be proportional. For example, for vertical, calc (or width) would be 60/[orig_height]x[orig_width]

So, my first question is how to obtain the original dimensions of a given image file?

Secondly, what is the easiest way to do this, considering that I'm using PHP/jQuery/SCSS? I'm leaning towards doing it all on the  PHP side.

Thank you.
0
Hi Experts,

I have a primary domain with WordPress, that is mainly content. Now I am building a custom PHP application in a subdomain, and I need to show a form from the subdomain in the primary one, with all includes, etc.

Is it possible to have a iFrame in WP (or anywhere for that matter), so it does not have scroll bars, but actually have a natural flow, sort of  overflow visible?

Any help will be appreciated.
0
Hi Experts

Could you point the better strategy to deploy a Laravel project at host ?

My hosting provider offers cPanel.

(I intend to do that to my own site)

Another option could be FTP - but I guess to transfer a complete Laravel project (with vendor folder) would be cumbesome to be done that way.

Thanks in advance.
0
Hi Experts      
            
Could you explain the meaning of this piece of Laravel code?

It was adapted from a legacy code due changes on table's structure.

      

		
$mes_atual = (int) date('m');	


        $compras = Compra::
                 leftjoin('periodos', 'periodos.id', 'compras.periodo_id')
                ->leftjoin('meses', 'periodos.mes', 'meses.mes')
                ->where('periodos.id', \DB::raw($mes_atual))
                ->groupBy('meses.id')
                ->select(DB::raw('(sum(grupo_a) + sum(grupo_b) + sum(grupo_c)  + sum(grupo_d) + sum(grupo_e) + sum(grupo_f) + sum(grupo_g)) as compraMensal'), 'meses.id')
                ->get();


        $totalDeMesesComCompra = $compras->count();

// What these parameters represents here?

$totalDeMesesComMetaBatida = $compras->reduce(function($quantidade, $item) use ($metasMensais){
  
  // This variable must to be redeclared here - otherwise it couldn't be found.... (?!)
  $mes_atual = (int) date('m');	

  $metaMes = $metasMensais
	  ->where('periodo_id', \DB::raw($mes_atual))
		->first();
		
	// The result of above query:
	// {"metaMensal":"139747.6600","periodo_id":2}
		
		
  if(empty($metaMes)){
	return $quantidade;
  }

  //   It results (1) if (true):  $metaMes->metaMensal >= $item->compraMensal 


  return $quantidade + ($metaMes->metaMensal >= $item->compraMensal);
}, 0);

Open in new window

           
            
            
		
$totalDeMesesComMetaBatida = $compras->reduce(function($quantidade, $item) use ($metasMensais){

  $metaMes = $metasMensais
			->where('mes', $item->mesreferencia)
			->where('ano', $item->anoreferencia)->first();
  
  
  if(empty($metaMes)){
	return $quantidade;
  }

  return $quantidade + ($metaMes->metaMensal >= $item->compraMensal);
}, 0);

Open in new window


Thanks in advance!
0
Hi Experts,

If you go to www.iwscc.ca you will see in the header 2 orange buttons: Corporate and Self-Registration, both going to #

Under WP Admin, I see that this theme is called Nonprofit, and the buttons are set in Theme Options >Address Bar, and ou will see in the snapshot that I can set the buttons label, but not the url. My questions are...

1- How do I remove the Corporate button? If I leave it blank, I just get an orange square.

2- How can I actually set an url to these?

I know I can create a child theme, and address #1 with CSS and #2 with JS, but I think there should be an easier way since the theme provides these buttons.

BTW- even though in the screenshot it says Webdivia, under themes it says Nonprofit. I just inherited this website.

Thank you,
wp admin
0
Hi Experts

Could you explain how an Laravel's Eloquent result could be used to operate another eloquent query?


This query:

$metasMensais = Distribuidormeta::

		  leftjoin('periodos', 'periodos.id', 'distribuidormetas.periodo_id')
		  
		  ->leftjoin('meses', 'periodos.mes', 'meses.mes')
		
		  ->where(function($q) use ($distribuidor_id, $distribuidorespermitidos_id){
			
			if($distribuidorespermitidos_id != null && count($distribuidorespermitidos_id) > 0){
			  $q->whereIn('distribuidor_id', $distribuidorespermitidos_id);
			}

			if($distribuidor_id != null && $distribuidor_id > 0){
			  $q->where('distribuidor_id', \DB::raw($distribuidor_id));
			}
			
		  })
		  ->where('periodos.mes', '>', \DB::raw(1))
		  ->where('periodos.id', \DB::raw($mes_atual))
		  ->groupBy('distribuidormetas.periodo_id')
		  ->select(DB::raw('sum(valor) as metaMensal'), 'periodo_id')  
		  ->get(); 

Open in new window



Results in:

[{"metaMensal":"139747.6600","periodo_id":2}]



After an Eloquent is aplied on the above result
$metaMes = $metasMensais
			->where('periodo_id', \DB::raw(2))
			->first();

Open in new window


But results in "null".

Is that correctly to use Eloquent this way?

Thanks in advance
1
When exporting a mobile number to csv, it is leaving off the first 0. I have tried various methods I found online to overcome this but none of them worked except one, well so I thought. It was to do this:

fputcsv($file, array('="'.$mobile_no.'"') );

Open in new window


On a Mac using Numbers this works perfectly. But some windows users have said that they can see "=""0551236373"" instead of just 0551236373 in the csv.

I also tried this but still no 0 is shown.

$mobile_test = sprintf('%01s', $mobile_no);

Open in new window


Any ideas?
0
I am trying to write a small application in PHP do download some content using curl in json format and process it.     Below is the data returned via curl and the error message I get when trying to walk through it.   I am sure it is something small I have done wrong I just cant see it.  

I appreciate any suggestions.  

<?php
$url = "https://website/records";
$apikey = '11111111111111111111111';
$ch = curl_init( $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-API-KEY: ' .$apikey, 'Content-Type: application/json' , 'Accept: application/json'));
$myout = curl_exec($ch);
curl_close($ch);


//$result = json_decode(json_decode($myout,true));
$result = json_decode($myout);
echo $myout;
$myResult = $result;

foreach($myResult as $value){
       echo $value->name . ",  " , $value->gender . "<br>\n";
}

?>

0
WordPress Query is very slow.

I inherited a site with one piece of custom code.  It basically grabs products from the Database and orders them and displays them through a shortcode.  The issue is, when I turn off the code the page loads very fast but with the code working it takes about 3 seconds to return the query to return.  I tried to switch over to the proprietary way that woo would grab products but it is still really slow.  Can anyone look at the following code and suggest how to speed it up?  I even thought of forcing the code to load last?

NOTE: if I change this to "Not Empty" it does not do what it is designed to do but it speeds up:
if ( empty($prodData) ) {


<?php
$shortcodeId = 'swift-cross-sell item-' . random_int(9999, 99999999);
$skus = explode(",", $atts['skus']);


//if( !is_admin() ){
  $cacheKey = 'key_products_' . implode('_', $skus);

 
$loopData = WC()->session->get( $cacheKey );


  if ( empty($loopData) ) {
    $args = [
      'post_type'  => ['product', 'product_variation'],
      'meta_query' => array(
        [
          'key'   => '_sku',
          'value' => $skus,
          'compare' => 'IN',
        ],
      )
    ];

    if ( ! empty( $atts['tag'] ) ) {
      $args['product_cat'] = $atts['tag'];
    }
    $loopData = new WP_Query( $args );
    WC()->session->set( $cacheKey , $loopData );
    
  }
//}
  


$loop = [];
while ( $loopData->have_posts() ) {
  $loopData->the_post();
  $productId = get_the_ID();
  

  //if( 

Open in new window

0
So, I'm on vacation and wanted to work a little bit on a project I'm trying to wrap up.

I bring my project on a separate drive, install it in my WAMP directory and go to run "php aristan migrate" and this is what I get:

brucegust@BRUCEGUST7EFC MINGW64 /c/wamp64/www/new_nomas (bruce)
$ php artisan migrate

Parse error: syntax error, unexpected '?' in C:\wamp64\www\new_nomas\vendor\lara
vel\framework\src\Illuminate\Foundation\helpers.php on line 500

brucegust@BRUCEGUST7EFC MINGW64 /c/wamp64/www/new_nomas (bruce)
$ php -v
PHP 5.6.40 (cli) (built: Jan  9 2019 15:10:36)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies

brucegust@BRUCEGUST7EFC MINGW64 /c/wamp64/www/new_nomas (bruce)
$ php artisan laravel

Parse error: syntax error, unexpected '?' in C:\wamp64\www\new_nomas\vendor\laravel\framework
\src\Illuminate\Foundation\helpers.php on line 500

Open in new window


I'm running PHP 7 on my box. The Laravel project I'm working on is also coming from a PHP 7 dynamic, so I don't know where the PHP 5.6.4 is coming from, but from what I've been able to determine, the error that I'm getting is because of PHP mismatch.

How do I fix it?
0
Dear Experts,
I use PHP
How can I post referenceCode and th variable in base64 format?
My code is below. Thank you

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL,"https://mylink");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,
            "referencecode=sdfsdf&th=sdfssd");

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$server_output = curl_exec($ch);

var_dump($server_output);

Open in new window

0
I've added a custom widget to a WordPress site that I'm currently updating, and have done so by adding the following code snippet to the functions.php file in my child theme:

function ts_custom_widget_setup() {	
	register_sidebar(
		array(	
			'name'	=> 'Disclaimer Text',
			'id'	=> 'disclaimer-text',
			'description' => 'Disclaimer Text',
			'before_widget' => '',
			'after_widget'  => '',
			'before_title'  => '',
			'after_title'   => '',
		)
	);	
}
add_action('widgets_init','ts_custom_widget_setup');

Open in new window


I'm now trying to add the widget's dynamic content to my footer.php file using the following:

<?php dynamic_sidebar('disclaimer-text'); ?>

Open in new window


... however, .. this is adding an unwanted HTML wrapper around the dynamic content, which I'm trying to eliminate:

<div class="textwidget custom-html-widget">testing dynamic disclaimer text</div>

Open in new window


How can I remove the "<div class="textwidget custom-html-widget"></div>" wrapper/html from the rendered HTML .. without adversely effecting the other dynamic widgets that I have in my bottom footer (which actually require those wrappers)?  Is there some way that I can do a search and replace using PHP?  If so, how?

For reference, .. I've been asked to make the fine print at the bottom of this page editable through the WordPress backend, .. which was itself easy to accomplish, .. but is proving to be difficult when rendering the dynamic output on the front end:

https://touchstoneliving.com/

Please advise.

Thanks,
-- Yvan
0
I have an html page and I want to use php includes in sections of it. Do I need to change the file extension from .html to .php for this to work?
0
Hi everybody.
I'm learning Laravel and I've got an issue with the Auth code. The issue is that Laravel seems to pretend that to register a new user all registration form fields be filled, even the not required ones.

This is my RegisterController.php
<?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use App\User;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Request;
use Illuminate\Auth\Events\Registered;

class RegisterController extends Controller
{
  /*
  |--------------------------------------------------------------------------
  | Register Controller
  |--------------------------------------------------------------------------
  |
  | This controller handles the registration of new users as well as their
  | validation and creation. By default this controller uses a trait to
  | provide this functionality without requiring any additional code.
  |
  */

  use RegistersUsers;

  /**
   * Where to redirect users after registration.
   *
   * @var string
   */
  protected $redirectTo = RouteServiceProvider::HOME;

  /**
   * Create a new controller instance.
   *
   * @return void
   */
  public function __construct()
  {
    $this->middleware('guest');
  }

  /**
   * Get a validator for an incoming registration request.
   *
   * @param  array  $data
   * @return 

Open in new window

0
form.php

Any example of modifying the PHP form such that when click different option of radio button, some of the HTML element will be changed, eg. Student ID will be changed to Customer ID, some HTML element will be hidden.

Thx
0
Hi Folks,

When printing an EE article, code snippets are jumbled up...they look like this:

print-bad
Gustav Brock submitted a bug report on this more than two years ago:
Code blocks of article print view are unreadable

The EE Mod at the time, Modalot, said this:
Ouch. That renders the printout almost useless. I've filed this internally as a major bug.
Not being aware of Gustav's bug report, I submitted one about two months ago:
Print feature at articles does not format code snippets properly

In response to my bug report, the same Mod (Modalot) informed me that it is an old bug and is "still unresolved". Being more than 2-1/4 years old and filed as a "major bug" by a Mod who has been an EE member for more than 10 years, it seems to me that EE is either incapable of, or not interested in, fixing the bug. As a result, I'm looking to the experts here for a workaround. I want to use the workaround to "print-to-PDF" my 63 EE articles and the Steps at my 47 EE video Micro Tutorials. Although that's 110 publications, only some of them have code snippets, so while I would prefer as automated a solution as possible, having to do some manual effort on each one is fine. I'm also fine with a solution that requires other products, such as Microsoft Word, or other commercial software. Thanks for your ideas! Regards, Joe
0
I want to extract a column from a nested array, example:

Array
    (
        [0] => Array
            (
                [id] => 11
                [order_id] => 6127
            )

        [1] => Array
            (
                [id] => 12
                [order_id] => 6123
            )

    )

This is what I need:

$results = array()
$results(6127, 6123)

I'd like to do this concisely eg with an array_map or similar

Copied from here as I have a similar question and it was not answered here:
https://stackoverflow.com/questions/8873146/how-to-extract-the-values-from-a-nested-array-into-another-array
0
hi, I'm trying to run some mySQL queries from php, to select records (from table e) which do not exist in another table (exg)

I would imagine any of these methods might work, but none are so I must be missing something fundamental, any suggestions?

SELECT e.ID FROM e WHERE NOT EXISTS (SELECT exg.ID FROM exg WHERE exg.ID=e.ID)
SELECT e.ID FROM e WHERE ID NOT IN (SELECT exg.ID FROM exg)
SELECT e.ID FROM e LEFT JOIN exg ON e.ID = exg.ID WHERE exg.ID IS NOT NULL

Open in new window


Thanks
0
Hi Experts,

When you go to http://selfregistration.iwscc.ca/admin/login/ under Chrome inspector you will see an iFrame named blockbyte-bs-sidebar

Does anyone has any idea when this is coming from and is anyone experiencing this?
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.