PHP

120K

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 Experts

Could you what means  this PHP code?

$dataref = date("d") == '01' ? date("Y-m-01", strtotime("last month")) : date("Y-m-01");

Open in new window


Thanks in advance
0
Amazon Web Services
LVL 13
Amazon Web Services

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

Need to understand $_SESSION variables in php (2 weeks into wrestling with php for the first time)

Trying to implement Google login to a student survey, accessed via gmail. Prior version worked with an LDAP login, using the variable username.

The google login code returns $userid. Then I was told to use $_SESSION['valid_user'], so I tried this:  $_SESSION['valid_user'] = $userid;. But haven't been able to get this to work.

Mainly I need to populate $username with $_SESSION['valid_user'] and use that for several MySQL statements.

For example - current MySQL code
-          $query = "SELECT * FROM sum_training WHERE student_id = ' ".$username." ' ";
-          $query = "INSERT INTO sum_training (student_id_with_tng_cycle, student_id, date_submitted) VALUES( '$username', '$student_id', '$timeOnly');";

I ended up with this for username: $_SESSION[2a, where it should have been sjones2a

Original code:    sessionStorage.setItem("student_id_with_tng_cycle", "<?php print($username) ?>");

Also, having a hard time debugging this, so if you have a good php debugging link at your fingertips, that will really help.
0
This url:

https://www.lakoshvac.com/devdev/adj_markup.php?fr=smod&mfp=Y&mval=.95&selno=3098

This result:

Parse error: syntax error, unexpected end of file in /home/lakoshva/public_html/devdev/adj_markup.php on line 13

php source run through https://phpcodechecker.com/. No errors

Source attached.

What is the issue, I cannot see it?
adj_markup.php
0
I have a data array that I will be encoding into JSON.  Part of the array includes nested values:

"lineItems": [
    {
      "itemNumber": "44672",
      "quantity": 4,
      "unitOfMeasure": "BDL",
      "description": "LANDMARK PRO"
    }
    {
      "itemNumber": "447506",
      "quantity": 3,
      "unitOfMeasure": "BDL",
      "description": "LANDMARK 30 AR METRIC SHINGLES"
    }
  ],

How do I display this in my data array: $data=array("lineItems" => " . . .").  I'm hoping this is simple, but I am new to PHP cURL and haven't been able to find a solution anywhere.  Thanks for your help!
0
I have tried 3 different iterations of pHp mail() to send HTML text with an attachment.
All fail.
Types of errors:
1. If I take out the attachment code, I do get an email.
2. I did get the full email with an attachment, but it was 0 bytes.
3. I got nothing, but stated email was sent. (Nothing in spam folder).

I am trying to send a PDF file that is on a server in "/img/pdfs/file.pdf" inside public/html/.

Here is the basic version:
<?php
/* Email Detials */
  $mail_to = "me@gmail.com";
  $from_mail = "me@mydomain.com";
  $from_name = "Russ";
  $reply_to = "me@mydomain.com";
  $subject = "Test Message";
  $message = "<email content>";
 
/* Attachment File */
  // Attachment location
  $file_name = "file.pdf";
  $path = "/img/pdfs/";
   
  // Read the file content
  $file = $path.$file_name;
  $file_size = filesize($file);
  $handle = fopen($file, "r");
  $content = fread($handle, $file_size);
  fclose($handle);
  $content = chunk_split(base64_encode($content));
   
/* Set the email header */
  // Generate a boundary
  $boundary = md5(uniqid(time()));
   
  // Email header
  $header = "From: ".$from_name." <".$from_mail.">".PHP_EOL;
  $header .= "Reply-To: ".$reply_to.PHP_EOL;
  $header .= "MIME-Version: 1.0".PHP_EOL;
   
  // Multipart wraps the Email Content and Attachment
  $header .= "Content-Type: multipart/mixed; boundary=\"".$boundary."\"".PHP_EOL;
  $header .= "This is a multi-part message in MIME format.".PHP_EOL;
  $header .= "--".$boundary.PHP_EOL;

Open in new window

0
Hello everybody,

I usually make MS SQL statements from two or more using JOIN or UNION, but normally when they all have a row in common (WHERE something IS somewhere). This time I need to do the same with 3 tables but saying what's NOT in another table.

Basically, I have a table for users, another table for notifications and a third table with the read status for each notification and each user. What I need to get are all the notifications that the user haven't read. I've attached an image with a simplistic view of my tables:

Simple design of tables
How can I do this?

Thanks in advance!
0
Hi!
I have a jSON POST that has a nested array in it and I need to figure out the syntax for sending it via PHP cURL.

The following is portion of my jSON POST:
"lineItems": [
    {
      "itemNumber": "string1",
      "quantity": 0,
      "unitOfMeasure": "string1",
      "description": "string1"
    }
    {
      "itemNumber": "string2",
      "quantity": 0,
      "unitOfMeasure": "string2",
      "description": "string2"
    }
  ],

How do I convert this section into my "$data = array( ... ) syntax?
0
Hi experts!  I'm trying to create a variable using an element of a json result.
The result is:

{"CreateOrderResponse":{"CreateOrderResult":{"OrderSubmittedFlag":1,"Response":{"ResponseCode":1,"ResponseMessage":"Order Created"},"Orders":[{"OrderID":1501001275,"ReportType":"Roof"}]}}}

I'm trying to create a php variable for the Order ID.  My code is:

$confirmation= $arr->CreateOrderResponse->CreateOrderResult->OrderSubmittedFlag->Orders->OrderID;

However, this is not working and it has me stumped.  Any help would be greatly appreciated!
0
this is a follow on to this question
https://www.experts-exchange.com/questions/29146040/Need-CSS-Help-On-WooCommerce-Custom-Add-to-Cart.html?headerLink=workspace_open_questions

Open in new window


The shortcode looks fine on
https://www.theherbsplace.com/which_calcium_is_best_for_you__sp_92/

Open in new window


but the button doesn't line up and the button color is different on this page

https://www.theherbsplace.com/unveiling_thai_go_sp_156/

Open in new window


This is my css code

.my-product { overflow: hidden; 
}
.my-product .product-image { 
	float:left; margin-right: 20px; 
} 
.my-product .product-price {
	position: relative;
	left:10px;
	float:left;
	top:60px;
}
.my-product .product-button  {
	float:left;
	position:relative;
	left:60px;
	top:40px;
}

Open in new window


I want to implement this shortcode throughout the site but it needs to look uniform on each page.  Please help me to find the problem.
0
I need help styling a custom add to cart url.  On this page, https://www.theherbsplace.com/which_calcium_is_best_for_you__sp_92/ right below Coral Calcium.

I tried this css code but it doesn't seem to even impact it.

.my-product  .woocommerce-Price-amount.amount {
	position:relative;
	right: 10px;
	top:10px;
}
.my-product woocommerce-Price-currencySymbol {
	position:relative;
	right: 10px;
	top:10px;
}

Open in new window


All I want is for every thing to be on the same line as the image and to the right of the image.  I want it in this order the image, the price then add to cart button.

This is the custom code that creates it

add_shortcode( 'cs_product', 'cs_product_callback');
function cs_product_callback($atts = []) {

    global $product;

    $atts = shortcode_atts( array(
        'id' => null,
    ), $atts, 'cs_product' );

    $product = new WC_product( $atts['id'] );

    $product_img = wp_get_attachment_image( $product->get_image_id(), 'woocommerce_gallery_thumbnail' );
    $product_button = do_shortcode( sprintf('[add_to_cart id="%d" style="" show_price="%s"]', $atts['id'], false) );
    $product_price = $product->get_price_html();

    ob_start();

    $output = <<< EOT
        <div class="my-product">
            <div>$product_img</div>
            <div>$product_price</div>
            <div>$product_button</div>
        </div>
EOT;

    echo $output;

    return ob_get_clean();
}

Open in new window


Thanks,
0
Become a Microsoft Certified Solutions Expert
LVL 13
Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

 $getString = "2018-09-17T17:02:10.898Z";

Open in new window


im using php how can i use php to split this into like below


2018-09-17

17 hour
02 min
10 seconds

? struggling for hour with preg_mach
0
https://www.facebook.com

Open in new window


how can i extract facebook from this url string in php ?
0
I have used this code here:

https://codex.buddypress.org/developer/loops-reference/the-members-loop/

and I want to filter users by certain criteria. The example for the bp-custom page is:

function my_custom_ids( $field_name, $field_value = '' ) {

  if ( empty( $field_name ) )
    return '';

  global $wpdb;

  $field_id = xprofile_get_field_id_from_name( $field_name ); 

  if ( !empty( $field_id ) ) 
    $query = "SELECT user_id FROM " . $wpdb->prefix . "bp_xprofile_data WHERE field_id = " . $field_id;
  else
   return '';

  if ( $field_value != '' ) 
    $query .= " AND value LIKE '%" . $field_value . "%'";
      /* 
      LIKE is slow. If you're sure the value has not been serialized, you can do this:
      $query .= " AND value = '" . $field_value . "'";
      */

  $custom_ids = $wpdb->get_col( $query );

  if ( !empty( $custom_ids ) ) {
    // convert the array to a csv string
    $custom_ids_str = 'include=' . implode(",", $custom_ids);
    return $custom_ids_str;
  }
  else
   return '';

}

Open in new window


Example Usage: Get all members who have filled out the xprofile field ‘dogs’ and selected the value ‘poodles’.

<?php if ( bp_has_members( my_custom_ids( 'dogs', 'poodles' ) ) ) : ?>

Open in new window

How do I add more conditions to the dogs/poodles. What If I also want 'birds', 'parrot' as well as 'dogs', 'poodles' ?
0
This is a follow on to this question
https://www.experts-exchange.com/questions/29145432/Need-WooCommerce-Product-Short-Code-That-Uses-Thumbnail.html#a42863437

Open in new window


This is the perfect size image but I also need it to show the price and an add to cart button.
0
 $trackedTreadIDs[] = array(
              'id' =>$getThreadIds['id']
            );

Open in new window


    
return implode(',', $trackedTreadIDs) ;

Open in new window



output  = testGM: "Array,Array"

it suspose to be two ids but displays array array ?
0
Hi there,

I have an issue with my woocommerce mini cart.

The issue I have is that there are a few items that seem to be stuck in the cart no matter if you are logged in or not. If you try and remove them, a few seconds later they appear again.

I thought It might have been outdated plugins and template files, so I have backed up my site and updated everything along with all the template files, still the same issue.

My website is www.ingeniousgifts.co.uk and you can access the slide out mini cart from the top right of the screen.

I have attached a screen record so you can see what happens.

I would really appreciate if someone could help me find out why this is happening and how to fix it?
Home---Ingenious-Gifts.webm
0
All of the sudden my posts do not show up properly and my navigation drops and you cant see it. I am a novice at WordPress, can someone please assist? The posts are all on the default template set up, which is what I have always used. The facts its affecting every page (other than the home page) makes me feel a setting is off.  Can someone please check out the site and advise?  Thank you!!

**UPDATE I figured out the posts but my navigation isnt showing in the proper spot on all pages except the home page like it use to. Is it maybe too many words?
wise-eats.com
0
Hi,
I'm sure its simply something obvious but I can't seem to figure it out:

I have a query in Laravel that I'm getting to retrieve all my users.

$users = DB::table('users')
      ->join('dealerships', 'users.dealership_id', '=', 'dealerships.id')
      ->join('roles', 'users.role_id', '=', 'roles.id')
      ->select('users.*','roles.*','dealerships.name')

Currently this returns all the users that are assigned to a dealership (records that have a value for users.dealership_id) . Problem is I need all the users regardless if a dealership has been assigned to them. I could skip the join, but I need the dealership name for those records that have a dealership assigned to them

if there someway to join the tables so I get all users and within my results also the dealership name for those that have one?



 Hope that makes sense. Thanks in advance.
0
this is a  follow-on to this question
https://www.experts-exchange.com/questions/29145248/Need-Custom-Short-Code-For-WooCommerce.html

Open in new window


The image is too large to be useful.  So, is there any way to programmatically create a short-code that does everything in the previous question but uses a thumbnail instead?

I found this
https://wordpress.stackexchange.com/questions/235313/add-the-post-thumbnail-url-to-a-shortcode-in-function-php

Open in new window

but I am not clear how to design what I need.
0
C++ 11 Fundamentals
LVL 13
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Sorry if I didn't post the code, but my question is purely theoretical.

I am creating an android app, where in the Login activity the login credentials are entered by the app automatically (after an authentication via SMS) in the EditText GONE and are sent to the server.

Is it a problem if the php code is vulnerable to SQL Injection?

Would some attacker be able to manipulate the hidden fields of my application?
0
  function getContacts(listId, cOnly) {

            if (typeof contactTable !== 'undefined')
                contactTable.destroy();
            contactTable = $('#contactstable').DataTable({
                "serverSide": true,
                "stateSave": true,
                "ordering": false,
                "searching": true,
                "oSearch": {"bSmart": false},
                "searchDelay": 1500,
                "ajax": {
                    "url": "get-contacts.php",
                    "type": "POST",
                    "data": {
                        listId: listId,
                        co: cOnly
                    }
                },
                "rowCallback": function (row, data) {
                },
                "initComplete": function (data) {
         
                },
                "columns": [
                    {"data": "contact"},
                    {"data": "email"},
                    {"data": "company"},
                    {"data": "date"},
                    {"data": "actions"}
                ],
                'columnDefs'        : [      
                { 
                    'searchable'    : false, 
                    'targets'       : [2,3,4] 
                }
            ],
                "order": [[0, 'desc']]
            });


     
        }

Open in new window



so this function creates my dataTable,

all works table it up, i only perform search functions on contact and email,

how ever it is failing to give me exact results , for example first record is  Tim Smith , i can clearly see Tim Smith, i type Tim Smith into the search input provided by data-tables, and he isnt shown in the result ?

https://datatables.net/
0
I need a shortcode for WooCommerce 3.6.2 that will show the image, price and add to cart button.  I found this shortcode [add_to_cart id="1984"] but it only shows the following:

https://gyazo.com/c1efad0e35b85a05227db4941ff6cd62

I saw this
https://stackoverflow.com/questions/19930779/woocommerce-custom-shortcodes

Open in new window

discussing how to do a custom shortcode via php.  I know some php but I am not that clear how to create what I am needing.

Thanks,
0
Hi,

I am upgrading my websites from php 5.6 to php 7.2 in my dev windows environment.  We are currently using php sql driver 3.2 and would need to upgrade to at least 5.2  if using php v7.2  

1. Any reason not to download the latest sql server driver which is 5.6 in terms of stability?

2. Most of our IIS sites (at least for now) will still be using php v5.6 , Is there any issue with having multiple php sql drivers installed, with some sites accessing the sql server through the 3.2 driver and others with 5.6?
0
 $created = date('d-m-Y',$setupCampaigns['TIMESTAMP']);
    

        if($setupCampaigns['TIMESTAMP'] < time() + 86400){
            $new = "<div class='new-eng-alert has-tooltip' data-original-title='null'>1</div>";
        } else {
            $new = "";
        }

Open in new window


how can i tell if this current timestamp is within the 24 hours old from the current timestamp,

if yes display new else dont.

for example if timestamp is 2 hours old from current show, if it is 25 hours dont show.
0
I'd like you to help me understand something about my code.

I am creating an android app in which there is a Login and Registration form.

I need to edit PHP files by adding PDOs.

I was able to get the PHP file to work with PDO, but there is a problem.

When the user registers, his name and surname are saved in the SharedPreferences and each time he accesses the monster.

The problem is that since I modified the PHP file by adding PDO, if I access for example with user1, it shows me the first and last name of user2, and if I log in with user2, user3, user4 always shows me the name and surname of user2 .

Why?

With the PHP file without PDO it shows me the name and surname of the user with whom I log in.

Can anyone explain why this happens?


Login.php without PDO

<?php

   if($_SERVER['REQUEST_METHOD']=='POST'){
       include_once("config2.php");

    $idAKr = $_POST['idAKr'];
    $cell = $_POST['cellulare'];

     if( $idAKr == '' || $cell == '' ){
            echo json_encode(array( "statusr" => "false","message" => "Inserisci numero di telefono!") );
     }else{
        $query= "SELECT * FROM Ristoratori WHERE cellulare='$cell'";
            $result= mysqli_query($con, $query);

            if(mysqli_num_rows($result) > 0){  
             $query= "SELECT * FROM Ristoratori WHERE 

Open in new window

0

PHP

120K

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.