PHP

118K

Solutions

32K

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

I'm trying to upload file from the PHP script on my local machine to a remote machine using cURL. The remote machine is running CentOS and connection to it is on https port  443.
When I use the same script to upload to a server with http port 80, it's working perfectly. But HTTPS is the issue. Below is my script:

PHP Script
<?php
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, 'https://10.32.0.17/receiver.php');
        curl_setopt($curl, CURLOPT_TIMEOUT, 30);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_CAINFO, 'C:/wamp64/bin/php/php5.6.19/extras/ssl/cacert.pem');
        curl_setopt($curl, CURLOPT_POSTFIELDS, $uploadRequest);
        $response = curl_exec($curl);
        $error = curl_error($curl);
        curl_close($curl);
        echo $response;
        echo $error;
?>

Open in new window


php.ini  - This is the php.ini on my local machine
curl.cainfo = 'C:/wamp64/bin/php/php5.6.19/extras/ssl/cacert.pem'

Open in new window

openssl.cafile='C:/wamp64/bin/php/php5.6.19/extras/ssl/cacert.pem'

Open in new window


Please what could be the issue? Do I need to do anything on the remote server?
0
Instantly Create Instructional Tutorials
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Can someone explain this code to me?

/*CALL Controllers CLASS IF EXIST*/

			if($row){ 

				$this->load->ClassValidation = false;

				$this->className = str_replace("-",'_',$row->slug);

				$this->load->controller( $this->className );

				if(method_exists( $this->load->{$this->className}, index ))

					$this->load->{$this->className}->index($data);

				else

					$this->load->view( $row->folder.'/'.$row->goto, $data ); //default

			}

			else

				$this->load->view( $row->goto ); //!$row- page not found

Open in new window


Thank you.
0
I have created a custom access right that connected a use->role->module->permission. Now there are certain attributes that I intend to retrieve from my database and use them across my angularjs+laravel application.

My front-end which is built using angularjs, I would like to call a function to retrieve the values in the following manner:

ifAccess('module','permission') //return true or false

The value should be stored as a global setting so that I do not have to make a call to the database off and on to obtain the values. I would only make a call to the database after login. How can I store and retrieve this values in the most secure manner.
0
I am trying to to provide basic information on an organization like : "Currently there are (variable) number of members".  I have no problems building tables or getting the queries to work in mysql.  I just can't transfer the variables into the php output.
0
I'm getting the error:
Warning: Composer should be invoked via the CLI version of PHP, not the cgi-fcgi SAPI

Not sure what this means or how to fix.  I have php 7.0 set on my cpanel settings.
0
The php artisan command was working fine.  

I just tried to create a new migration file and it failed with:
 [ErrorException]
  Invalid argument supplied for foreach()

Open in new window


Even if I run "php artisan list" it fails with the same error.  I don't know what I did.  How can I track down what is causing the issue?
0
Is there some trick to getting the translation working? "AS" in the query below fails...

Here is the Query:

SELECT c.FirstName AS first_name,
             c.LastName AS last_name,
             c.Company AS company_name,
             r.RepID AS rep_id,
             r.RepName AS rep_name,
             c.CustomerID AS om_customer_id
FROM Customers c
LEFT JOIN RepManufacturer r ON r.RepID = c.Integer5
WHERE (c.FirstName LIKE '%todd test%' OR c.LastName LIKE '%todd test%' OR c.FullName LIKE '%todd test%' OR c.Email LIKE '%todd test%' OR c.Phone LIKE '%todd test%' OR c.Company LIKE '%todd test%')

Which gives me this array result on our Unix Ubuntu web server.. so basically it just totally ignores the ‘AS’ and retains the orginal name

Array ( [0] => Array ( [FirstName] => Todd testing [LastName] => Sprind testing [Company] => OurCompany [RepID] => 658 [RepName] => Dan The Man [CustomerID] => 2171 ) [1] => Array ( [FirstName] => todd TEST [LastName] => sprind TEST [Company] => ourcompany.com [RepID] => [RepName] => [CustomerID] => 2172 ) [2] => Array ( [FirstName] => TEST Todd [LastName] => TEST Sprind [Company] => [RepID] => [RepName] => [CustomerID] => 2242 ) [3] => Array ( [FirstName] => test todd [LastName] => test spri [Company] => residential [RepID] => [RepName] => [CustomerID] => 2702 )
0
Hi,

I've been using the below code for sometime, all works well, except when there is an insert or edit query - I get a blank page.
It could be because it's trying to add/edit a field that may not exist in the database or an SQL error - but I do not get feedback on screen - the page usually just loads blank.  Should I be using different code, alter it, or something completely different?

$db_host = "ip";
$db_user = "admin";
$db_name = "database";
$db_pass = "pass";

$link = mysqli_connect($db_host, $db_user, $db_pass) or die(mysql_error());
mysqli_select_db($link,$db_name) or die(mysql_error());

Open in new window


QUERY
$sql = mysqli_query($link,"SELECT * FROM table") or die(mysql_error());
$row = mysqli_fetch_array($sql);
$total = mysqli_num_rows($sql);

Open in new window


INSERT
mysqli_query($link,"INSERT INTO table (test) VALUES ('1')");

Open in new window


UPDATE
$result = mysqli_query($link,"UPDATE table SET test='1',WHERE id = '1'") or die(mysql_error());

Open in new window


Or is it a PHP setting i need to turn on to properly show me the SQL error?

Thank you
0
I'm helping my friend to troubleshoot this.

Apparently his website is facing these errors:

Warning: include(application/views/themes/ecig/header.php): failed to open stream: No such file or directory in /home/cccccccccc/public_html/wwwwwwww.com/system/classes/loader.php on line 59

Warning: include(application/views/themes/ecig/header.php): failed to open stream: No such file or directory in /home/cccccccccc/public_html/wwwwwwww.com/system/classes/loader.php on line 59

Warning: include(): Failed opening 'application/views/themes/ecig/header.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/cccccccccc/public_html/wwwwwwww.com/system/classes/loader.php on line 59

Warning: include(application/views/themes/ecig/notfound.php): failed to open stream: No such file or directory in /home/cccccccccc/public_html/wwwwwwww.com/system/classes/loader.php on line 60

Warning: include(application/views/themes/ecig/notfound.php): failed to open stream: No such file or directory in /home/cccccccccc/public_html/wwwwwwww.com/system/classes/loader.php on line 60

Warning: include(): Failed opening 'application/views/themes/ecig/notfound.php' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/cccccccccc/public_html/wwwwwwww.com/system/classes/loader.php on line 60

Warning: include(application/views/themes/ecig/footer.php): failed to open stream: No such file or directory in 

Open in new window

0
By default you can get the list of post titles followed by the date of the post. As shown below. However as in the second list I would like a list but with breaks in the list to show when the month has changed. How is this possible.

Post 1 title
Post 1 date
Post 2 title
Post 2 date
Post 3 title
Post 3 date
Post 4 title
Post 4 date
Post 5 title
Post 5 date
Post 6 title
Post 6 date

What I want is :

July 2017
-
Post 1 title
Post 1 date
Post 2 title
Post 2 date
Post 3 title
Post 3 date

June 2017
-
Post 4 title
Post 4 date
Post 5 title
Post 5 date
Post 6 title
Post 6 date

Thanks
0
Don't Cry: How Liquid Web is Ensuring Security
Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

This function along with the PHP is sending the email.  What it is not doing is hiding the form and saying "Thanks"...so it is only half working!

The Function
<script>
$(function() {
  $("#myform").on('submit', function(e) {
    e.preventDefault();
    $.ajax({
      url: 'send_mail.php',
      dataType: 'json',
      data: $("#myform").serialize()
    }).done(function(d) {
      if (d.success==true) {
        $("#myform").hide();
        $("#results").text("Thanks!").show();
      }
    });
  });
});
</script>>

Open in new window


The PHP
<?php

$webmaster_email = "ds@mediascrubber.com";
$email_address = $_REQUEST['email_address'] ;

function isInjected($str) {
	$injections = array('(\n+)',
	'(\r+)',
	'(\t+)',
	'(%0A+)',
	'(%0D+)',
	'(%08+)',
	'(%09+)'
	);
	$inject = join('|', $injections);
	$inject = '/$inject/i';
	if(preg_match($inject,$str)) {
		return true;
	}
	else {
		return false;
	}
}

if (!isset($_REQUEST['email_address'])) {
header( "Location: $feedback_page" );
}

elseif ( isInjected($email_address) ) {
header( "Location: $error_page" );
}

else {
mail( "$webmaster_email", "Feedback Form Results", "From: $email_address" );
header('Content-Type: application/json');
echo json_encode($data);

}
?>

Open in new window

0
My var_dump on the array that gets passed is:
array(6) {
  ["_token"]=>
  string(40) "zQ2tv4UljUsdwd7MeA6aKQW1PMQBBEOhB1EDFrc5"
  ["airline"]=>
  array(3) {
    [0]=>
    string(1) "1"
    [1]=>
    string(1) "4"
    [2]=>
    string(1) "2"
  }
  ["flightNumber"]=>
  array(3) {
    [0]=>
    string(1) "1"
    [1]=>
    string(1) "4"
    [2]=>
    string(1) "6"
  }
  ["departing"]=>
  array(3) {
    [0]=>
    string(18) "07/24/2017 1:58 PM"
    [1]=>
    string(18) "07/29/2017 1:58 PM"
    [2]=>
    string(18) "07/26/2017 1:59 PM"
  }
  ["seatNumber"]=>
  array(3) {
    [0]=>
    string(1) "1"
    [1]=>
    string(1) "4"
    [2]=>
    string(2) "55"
  }
  ["tripID"]=>
  string(2) "22"
}

Open in new window


How would I loop these and still keep their association for inserting.  

For example all of the arrays with the "0" key are associated, same with "1", "2".
0
Hello

I'm busy on a project where i have read only access to an oracle database.
Got a running webserver (LAMP) with a running OCI8 connection.
I'm trying to get a select query result from the following:

TableA
ID
DOC_ID
Date
Type

TableB
ID
DOC_ID (references tableA)
FILE_NAME
FILE_ID
FILE_TYPE

TableB can contain more then one result for the same DOC_ID.

The goal is to get the data from TableA appended with the results from TableB where the DOC_ID is the same and get them into a JSON format.
Looking like

{
	"data": [{
		"ID": "123456",
		"DOC_ID": "789456",
		"Date": "2/1/2016",
		"Type": "PI",
		"FILE_NAME": [
			"File1.pdf", "File2.docx"
		],
		"FILE_TYPE": [
			"PDF", "DOCX"
		],
		"FILE_ID": [
			"453215", "654687"
		]
	}, {
		"ID": "544569",
		"DOC_ID": "001223",
		"Date": "2/8/2016",
		"Type": "PI",
		"FILE_NAME": [
			"File1.txt"
		],
		"FILE_TYPE": [
			"TXT"
		],
		"FILE_ID": [
			"453215"
		]
	}, {
		"ID": "2225599",
		"DOC_ID": "0148966",
		"Date": "2/1/2017",
		"Type": "PI",
		"FILE_NAME": [
			"File1.xml", "File2.xml", "File3.xml"
		],
		"FILE_TYPE": [
			"XML", "XML", "XML"
		],
		"FILE_ID": [
			"00147788", "00114455", "00113210"
		]
	}]
}

Open in new window


Any advise on how to best go about this is welcome.
0
Hi,
I am developing a small friend contact list for my personal website, wherein I want my friends to update their personal details, like address, city, phone number, email address etc. after login.
There are fields like address, city, phone No., email, which is editable and fields like Names are not editable.
Flow:
login.php-->mainpage.php [where all the fields are getting displayed in column-wise like:
      First Name:
      Last Name :
      Address     :
      City             :
      Phone        :
      Email         :

To edit or update the details, I create a link 'EDIT' Button and link it to a page 'edit_profile.php', where I want my friends to update their latest information. But, the code is not working - I am developing this myself with the help of Internet. May I request you to kindly look into this and correct, it would be a great learning experience for me.

[edit_profile.php] is attached below:
<?php
session_start();
$first_name = $_SESSION['first_name'];
$last_name  = $_SESSION['last_name'];
$Fri_Add1  = $_SESSION['Fri_Add1'];
$Fri_City  = $_SESSION['Fri_City'];
$Fri_Phone1  = $_SESSION['Fri_Phone1'];
$Fri_Email1  = $_SESSION['Fri_Email1'];


if(!isset($_SESSION['restrict'])){
header("Location: ../login.php");
}

include "database/friends.php";
$sqlInfo = mysql_query(" select * from `friends`");

if(isset($_POST['updateMessage'])){

include 'database/friends.php';
$updateMessage = trim($_POST['updateMessage']);
$first_name = …
0
i want to be able to hide the edit and the delete link for guest users for example.
i am using the &_section['login_user']; variable to manage users that login. i have succeeded in limiting access to some of the components on the page but don't know how to limit access to the edit and delete link.  thanks in advance for your help!!!

 <?php
while($row=mysqli_fetch_array($result)){
	?>
	<tr>
	<td><?=$row['name']?></td>
	<td><?=$row['fname']?></td>
	<td><?=$row['lname']?></td>
	<td><?=$row['address']?></td>
	<td><?=$row['phonenumber']?></td>
	<td><?=$row['sex']?></td>
	<td><?=$row['position']?></td>
	<td><a href="editstaff2.php?edite=<?php echo $row['staff_id']?>">edit</a>|<a href="ui-table-advanced3.php?delet=<?php echo $row['ngo_id']?>">delete</td>
	
	</tr>
	
	<?php
}
?>

Open in new window

0
Hi experts, i want to change PHP to POWERBUILDER, any help please!
below the php script :

========encrypt===============
function mc_encrypt($data, $key)
{
/// make binary representasion of $key
$key = hex2bin($key);

/// check key length, must be 256 bit or 32 bytes
if (mb_strlen($key, "8bit") !== 32) {
throw new Exception("Needs a 256-bit key!"); }

// create initialization vector
$iv_size = openssl_cipher_iv_length("aes-256-cbc");
$iv = openssl_random_pseudo_bytes($iv_size);

/// encrypt
$encrypted = openssl_encrypt($data, "aes-256-cbc", $key, OPENSSL_RAW_DATA, $iv );

/// create signature, against padding oracle attacks
$signature = mb_substr(hash_hmac("sha256", $encrypted,  $key,   true),0,10,"8bit");

/// combine all, encode, and format
$encoded = chunk_split(base64_encode($signature.$iv.$encrypted));

return $encoded;
}

========decrypt===============
function mc_decrypt($str, $key)
{

/// make binary representation of $key
$key = hex2bin($key);

/// check key length, must be 256 bit or 32 bytes if (mb_strlen($key, "8bit") !== 32) {
throw new Exception("Needs a 256-bit key!"); }

/// calculate iv size
$iv_size = openssl_cipher_iv_length("aes-256-cbc");

/// breakdown parts
$decoded = base64_decode($str);
$signature = mb_substr($decoded,0,10,"8bit");
$iv = mb_substr($decoded,10,$iv_size,"8bit");
$encrypted = mb_substr($decoded,$iv_size+10,NULL,"8bit");

/// check signature, against padding oracle attack
0
What is the cause of this error fsockopen failed No route to host (113) while publishing a template to my domain? I tried using another third party template provider and i received an FTP passive Mode error. What is the cause and what is the solution. Please help.
0
Basically i want to store and be able to download word, excel pdf et.. file in mysql database. i have succeeded in storing the files but the download aspect is giving me hell. i wrote the script to down the files, but every time the downloaded files gets damage or corrupt. This is the error when i attempt to open the downloaded microsoft office document: we are sorry we can not open the file because we found problem with it content. this file is corrupt and can not be open.


please help, i have been on this for days.

this is my downlo.php file

if(isset($_GET["dow"])){
      ob_start();
      $path = $_GET['dow'];
      $mysqli = new mysqli("localhost","root","","extenderaid");
if($mysqli-> connect_error)
      die("database connection fail".$mysql->connect_error);

$qry = mysqli_query( $mysqli,"select doc from document where doc= '$path'");
header('Connection: Keep-Alive');
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($path).'"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($path));
ob_clean();
readfile($path);

}




this is my upload file
include('section.php');
  
 $fload_error='';
  $discription_error='';
$discr='';
$submis_error='';
$submis='';
$ngo_error='';
$success='';
$target_file 

Open in new window

0
So on this page I have the ability to clone multiple inputs depending on how many flights a user has:

http://groupplanner.gallitin.com/flight/create?tripID=22&tripName=ABC&depart=07%2F20%2F2017&return=08%2F05%2F2017

When I try to submit that of course it bombs as originally it was not an array and only allowed a single input.

Current code:
public function store(Request $request){

        $flight = new Flight;
        $flight->airline = request('airline');
        $flight->flightNumber = request('flightNumber');
        $flight->departing = date('Y-m-d H:i:s', strtotime(request('departing')));
        $flight->seatNumber = request('seatNumber');
        $flight->tripID = request('tripID');
        $flight->userID = Auth::id();
        $flight->save();
        $tripID = request('tripID');
        $tripName = request('tripName');

        return redirect()->route('flight', ['tripID' => $tripID,'tripName' => $tripName]);

    }

Open in new window


How can I modify this since I now have the data coming across as an array?  Is it just a normal foreach loop like I would do in PHP or is there a better/easier method to do with Laravel and Eloquent?
0
WordPress Tutorial 2: Terminology
WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

I had this question after viewing SQL How do I INSERT INTO two tables at once and pass the ID from the first to the second.
Dealing with two tables: product and product_volume.
I have a dynamic form, how do i insert into the product table and use the ID created to populate product_volume in one query (in a php function). I need to create multiple rows for 1 product ID which will have different volumes and prices.
0
I know how I can get the data needed, but want to follow Laravel/MVC practices here and new to it.

I have a page that stores data that a user sends through a form.  Once they submit they are redirected to a new page that I'd like to display some of the data back to them.

For example, currently any data I want to display I'm just passing in the URL.
$trip = new Trip;
        $trip->tripName = request('tripName');
        $trip->departing = date('Y-m-d H:i:s', strtotime(request('departing')));
        $trip->returning = date('Y-m-d H:i:s', strtotime(request('returning')));
        $trip->save();
        $tripID = $trip->id;
        $tripName = request('tripName');

        return redirect()->route('flight', ['tripID' => $tripID,'tripName' => $tripName]);

Open in new window


Then within the view I just:
{{ $_GET['tripName'] }}

Open in new window


Is that how I should be doing it?  Or when they hit the new view is there an easy way to grab that data with a DB call?  If so should this be done in the view or do I need to serve somehow from the controller?

Thanks
0
I would like to make a parse of postfix mail log in an HTML/PHP page with a search bar and then creating a dynamic table with all these tags. when the table is done I should be able to click on the "Date" and another page should open with others info about that log *(2)

I will copy an example of a log

search: from: ...... to: ...... date: from: .... to: ....

Eg Table example: Date | time | from: Jack | to: John | status:

*(2)

client:
message
id:
Size:
relay:
delay(s)
status detail
KLMS:
av-reason:
ap-reason:
as-reason:
cf-reason:
action:
rules:



809318:Jul 11 14:13:50 amail-2014 postfix/smtpd[17127]: 78F5E83F28: client=mx0a-00164e02.pphosted.com[67.231.149.89]
809320:Jul 11 14:13:50 amail-2014 postfix/cleanup[18135]: 78F5E83F28: message-id=<ADR420000021230890209457A56BCF141EE799C64C575B380E1C@molex.com>
809324:Jul 11 14:13:50 amail-2014 postfix/qmgr[27711]: 78F5E83F28: from=<NO-REPLY@MOLEX.COM>, size=30390, nrcpt=1 (queue active)
809325:Jul 11 14:13:50 amail-2014 postfix/smtp[11782]: 78F5E83F28: to=<*****@SYLEX.SK>, relay=mail1.sylex.sk[195.168.126.227]:25, delay=0.73, delays=0.59/0/0.01/0.13, dsn=2.6.0, status=sent (250 2.6.0 <ADR420000021230890209457A56BCF141EE799C64C575B380E1C@molex.com> [InternalId=50607599648815, Hostname=SYXEX01.sylex.sk] Queued mail for delivery)
809326:Jul 11 14:13:50 amail-2014 postfix/qmgr[27711]: 78F5E83F28: removed
809323:Jul 11 14:13:50 amail-2014 KLMS: not processed: …
0
I need to palace DOB in text format only so i wrote the code like this but i need some validation like DD should be upto 31 days only,MM should be upto 12 months and similarlu YYYY also
  DOB<input  pattern="^([0-9]{02}/[0-9]{02}/[0-9]{4})" type="text" placeholder="DD/MM/YYYY"></td>

Open in new window

0
Hello Everyone,
I have one issue about PDF file.
I generate dynamic PDF template(Like Certificate). The file content some fields like Firstname,Lastname,Course type,etc.
I want to write dynamic content into PDF as firstname, lastname etc.

I have tried MPDF,FPDF etc tools but that's not working.Also used PDF to html conversation but after converting HTML regenerates not possible from html into proper format.

Please let me know if anyone have other idea to direct replace content into Existing pdf using PHP.
I have sample pdf files.
I want to replace content into given attachment.
This is demo file i have many files with different templates.
Waiting for help.
Certi-FWT-basis-en-opfris_PDF.pdf
0
please look attached file.i need to print the data individulaly
i created two tabular forms in phpmyadmin those two are linked data is fetching here the problem is while fetching the data i'm getting the employess data continusly.
for example : i created two tables one is employee family and other one is employee personal.while fetching the data all employees family details are fetching at a time similarly personal details comming like that but i want in order
<h3 style="font-size:10%;"><h3 style="text-align:center;color:black;">EMPLOYEE INFORMATION</h3>
<?php
 $dbhost = "localhost";
 $dbuser = "GCSADMIN";
 $dbpass = "123456";
 $db = "employee_db";

    $conn = mysql_connect($dbhost, $dbuser, $dbpass,$db);

   if(! $conn ) {
      die('Could not connect: ' . mysql_error());
   }

   $sql = "SELECT EmployeeID,FirstName,MiddleName,LastName,FatherName,SpouseName,MotherName,DOB,Age,BloodGroup,MaritalStatus,Gender,ContactNumber,EmergencyContactNumber,Email,DateOfJoiningatGemini,TotalYearOfExperience,ReleventYearOfExperience,PANnumber,PassportNumber,UANnumber,AadharNumber,PresentAddress,PermanentAddress FROM employee_information";

   mysql_select_db('employee_db');
   $retval = mysql_query( $sql, $conn );
   if(! $retval ) {
      die('Could not get data: ' . mysql_error());
   }
   
   echo "<table border='5px solid block', align='center', width='50%', padding='12px 20px' >";

   while($row = mysql_fetch_assoc($retval, MYSQL_ASSOC)){

     ?>
     
            <tr><th 

Open in new window

0

PHP

118K

Solutions

32K

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.