PHP

118K

Solutions

126

Articles & Videos

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

Hi

I am running a PHP script that generate a list of variables, merges them into a email template and sends it through Manrdill Mailchimp's transactional email system).

The process might loop for several thousand iterations to generate all the emails that need sending.

The script that I am using:

//generate data for all records
while($row = sqlsrv_fetch_array($result, SQLSRV_FETCH_ASSOC)){
//populate some additional tables with info for each record
//merge each record into the email template
//send email
//update record to show that it has been emailed
}

This runs through all the records then snds the emails/updates the table etc. Depending on the number of records, this can take quite some time to process.

I have extended the PHP timeout and max-memory size to cope, but would prefer a better solution.

Would the ob_start() / ob_get_clean()  functions help by processing each record individually and not storing everything up in memory, potentially over loading the buffer/memory and then outputting everything.

If someone can advise if this is a good idea or not and how I should implement it, I'd be very grateful.

Thank you in advance
0
Why Off-Site Backups Are The Only Way To Go
Why Off-Site Backups Are The Only Way To Go

You are probably backing up your data—but how and where? Ransomware is on the rise and there are variants that specifically target backups. Read on to discover why off-site is the way to go.

Hello experts,

Need some help

We have migrated a website from cpanel accelerated2 to another hosting provider who provided latest version of cpanel. The transfer was successful. However while browsing the website we are seeing below error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@xxxx.com to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

I have gone through the error logs in cpanel which is logging below error everytime the domain is accessed.

corealert: pid xxxxx /home/xxx/public_html/.htaccess unknown filter provider deflate

At first we though php version 5.4 not installed is the issue, we have installed 5.4 via cpanel and restarted the http webserver but still same error.

Unable to understand where to look for

Any help is appreciated.

Thank you

best regards
0
How can I tell if a string is already encoded with base64?

When I run the example below it says it is base64 but it is not. When I send actual base64 encoded string it says it is base64 encoded as well. I understand how to decode base64 but I need a way to check if a string is really base64 or plain text so I know to decode it or not.

$data = 'This is a test';

if (base64_decode($data, true) === false) {
        echo 'Not a Base64-encoded string\n\n';
} else {
        echo 'Yes it is a base64 encoded string\n\n';
}

Open in new window

0
Without having to use YouTube. I would like to know and learn how to transcode videos. What are some great places to learn?
0
So, I am really trying to get my head around JSON and I have tried this which works but I wanted to know if there is a better way to do it or if this okay. I am actually playing around with developing a hybrid mobile app which uses a php and mysql backend. I have to use ajax to retrieve data and I want to also use JSON.

This is the jQuery/Ajax. The double dollar signs are not a typo, that is the correct syntax for the application but it is identical to jQuery as far as I know.

$$( "#submit" ).click(function(e){
		$$.ajax({
			url:"content.php",
			type:"POST",
			dataType:"json",
			success: function(data) {
				var len = data.length;
				for(var i = 0; i<len; i++) {;
					var user_name = data[i].user_name;
					$$( "#phpcontent" ).append(`
					<li class="item-content">
						<div class="item-inner">
						<div class="item-title">${user_name}</div>
						</div>
					</li>
					`);
				}
			}
		});
	});

Open in new window


This is the php for content.php

$stmt = $link->prepare("SELECT `user_name` FROM `users` ORDER BY `user_name` DESC");
$stmt->execute();
$result = $stmt->get_result();
$numRows = $result->num_rows;
if($numRows > 0) {
	while($row = $result->fetch_assoc()) {
		$user_name = sanitize($row['user_name']);
		
		$return_array[] = array(
		
			"user_name" => $user_name
		
		);
	}
}
$stmt->close();
echo json_encode($return_array);

Open in new window


What I have noticed in all the examples I have looked at is that the database results have to be put into an array in order to use json_encode. Am I correct in saying that or is it just a coincidence that every example I looked at did that?
0
hai...in phpmyadmin data base table my DOB is coming in adding foramt...did i need to change the type...???

my code in php format:

 $DOBMonth = false;
if(isset($_POST['DOBMonth'])){
    $DOBMonth = $_POST['DOBMonth'];
 }

$DOBDay = false;
if(isset($_POST['DOBDay'])){
    $DOBDay = $_POST['DOBDay'];
 }

$DOBYear = false;
if(isset($_POST['DOBYear'])){
    $DOBYear = $_POST['DOBYear'];
 }


$DateOfBirth=$DOBMonth+"/"+$DOBDay+"/"+$DOBYear;
0
Hello
I am using a script that backups and restores mysql databases. The script works fine until I include an external JS file, which is when I get the title error in firebug. There is a lot of code but I think I can narrow the error to line 692 but what ever I try, I keep getting the error.

I must add I never created the script so cannot give any further info on it's content, but it does what I want it to do, apart from this error.

I would be grateful if somone could help with this. Many thanks

<?php

// Report errors

error_reporting(E_ERROR | E_PARSE | E_NOTICE);

// error_reporting(E_ALL);	//Debug purpose

$host = 'localhost'; //HOST;//eg:localhost
$username = 'root'; //USER;//self explanatory
$passwd = ''; //PASSWORD;//self explanatory
$charset = 'utf8'; //charset keeps preferred character encoding
$port = '3306'; //self explanatory
$dateformat = 'd-m-Y H-i-s-A'; // will be appended to database backup file name eg:test_2016-Oct-25-10-30-54-AM.zip

// small utility function to detect whether secured server or not

function isSiteSSL()
{
  return (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443;
}

$url = (isSiteSSL() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

if (isset($_SERVER['QUERY_STRING'])) {
  $url = str_replace('?' . $_SERVER['QUERY_STRING'], '', $url); //removing query string to get exact url
}

$url2 = $url; //$url2 used for building download url
$url.= 

Open in new window

0
If $_SERVER vars are an array, what would the code look like to access each var such as 'REQUEST_TIME'?
0
With the following code in place:

 <?php echo $form->dropDownListRow($model, 'specialty_id', DoctorSpecialty::listOptions()); ?>

How would I limit the possible choices to just two of four?  I can't delete the other two from the table because they are used in the database in other places.
0
I added codeigniter 'table' to my project and i got desired outcome for view except for the fact that the way i had it before i was able to delete record by clicking on them since they were anchor tags, i would like to know how to recreate this in new table format. Thanks!
site_model.php
site.php
options_view.php
Capture2.PNG
Capture.PNG
0
Independent Software Vendors: We Want Your Opinion
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

How can i show my url path in my body tag
If i am on a page example.com/abhinav
How can i show "abhinav" in<body>You are at "abhinav"</body>

and i also want a form action type code when i write in it like my name and click submit so it opens url.com/myname
i mean just whatever i write in form action that shows me in my url after slash
0
Hello
I am struggling to convert a date that I use as part of a filename of a zip file. At the moment it prints
bootstrap_21-Jun-2017-16-04-09-PM.zip
but I need to have it print
bootstrap_21/06/2017 16-04-09-PM.zip

I have posted the code I am using and would be grateful if someone could help with this. Thanks

$dateformat='d-M-Y-H-i-s-A';

case 'backupfile':
    echo    $_POST['db'].'_'.date($dateformat, time());					
break;

Open in new window

0
I have linux server and i want to count pdf pages is colored or bw.

i have used imagemagic but it takes serverd down so can you help me with alternative way?
0
As some people have encountered the need to decompress a response I got from a PHP request. I've found how to do that - assuming you have control of the request and you can set the Accept-Encoding header.
0
Hello,
I have downloaded and installed wamp on my system but I can't connect to phpmyadmin though I write "localhost/phpmyadmin" in the url.
I really need your helps .
thanks.
0
I have attached files, i am trying to display results in a table, i am new to codeigniter is there a way to do this? what would be the best way to implement this? i have read about codeigniter tables but i am not sure how to apply to my code. Any guidance will be appreciated.
Thank You!
site.php
site_model.php
options_view.php
0
See my below code.

$query_rs_media_new_group = "SELECT supplier_code, title, url, description, description_item, brand, type, weight, category, section, width, label_artwork, min(id) as id 
							 FROM media_new 
							 WHERE media_binder = '1'
							 GROUP BY title 
							 ORDER BY brand";
$rs_media_new_group = mysql_query($query_rs_media_new_group, $conn_cmyuk) or die(mysql_error());
$row_rs_media_new_group = mysql_fetch_assoc($rs_media_new_group);
$totalRows_rs_media_new_group = mysql_num_rows($rs_media_new_group);

Open in new window


The order by brand is not coming out in the correct order. Could this be something to do with the alias or group by?
0
Hi,

I keep getting an error

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[08001] SQLDriverConnect: 0 [unixODBC][FreeTDS][SQL Server]Unable to connect to data source'

Here is my log:

[ODBC][25605][1497970106.192244][__handles.c][450]
		Exit:[SQL_SUCCESS]
			Environment = 0x1ab5550
[ODBC][25605][1497970106.192302][SQLSetEnvAttr.c][182]
		Entry:            
			Environment = 0x1ab5550            
			Attribute = SQL_ATTR_ODBC_VERSION            
			Value = 0x3            
			StrLen = 0
[ODBC][25605][1497970106.192331][SQLSetEnvAttr.c][349]
		Exit:[SQL_SUCCESS]
[ODBC][25605][1497970106.192355][SQLSetEnvAttr.c][182]
		Entry:            
			Environment = 0x1ab5550            
			Attribute = SQL_ATTR_CP_MATCH            
			Value = (nil)            
			StrLen = 0
[ODBC][25605][1497970106.192378][SQLSetEnvAttr.c][349]
		Exit:[SQL_SUCCESS]
[ODBC][25605][1497970106.192405][SQLAllocHandle.c][364]
		Entry:
			Handle Type = 2
			Input Handle = 0x1ab5550
[ODBC][25605][1497970106.192431][SQLAllocHandle.c][482]
		Exit:[SQL_SUCCESS]
			Output Handle = 0x1ab5ba0
[ODBC][25605][1497970106.192462][SQLSetConnectAttr.c][321]
		Entry:            
			Connection = 0x1ab5ba0            
			Attribute = SQL_ATTR_AUTOCOMMIT            
			Value = 0x1            
			StrLen = -6
[ODBC][25605][1497970106.192497][SQLSetConnectAttr.c][504]
		Exit:[SQL_SUCCESS]
[ODBC][25605][1497970106.192527][SQLSetConnectAttr.c][321]
		Entry:            
			Connection = 0x1ab5ba0      

Open in new window

0
Hi,

I'm using PHP and dblib to connect tp a MS SQL server data base, i can connect and talk to the database fine but I'm finding it hard to pull a single row of data or a single entry

$con = new PDO("dblib:host=****;dbname=nursery",'pcbuddy','****');

Open in new window


foreach($_POST['selectedinvoices'] as $ids)
{
				
				$query_today = $con->prepare("SELECT * FROM Invoices WHERE invoice_no = :ID");
				$query_today->bindParam(':ID', $ids, PDO::PARAM_INT);
				$query_today->execute();
									
				echo $stmt["invoice_no"];

Open in new window


No matter what I try I cant do a single select query.

Please help
0
Creating Instructional Tutorials  
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

i want to generate bunch of barcode with different data in php in same page on single click.
i try or learn many source code but only single barcode will be print using php but i want multiple barcode generation code so will you please help me to solve this asap.
Thank You !!!
0
I am use the COM in php to generate the excel report.
the server is the windows server 2012 R2, office2013 professional plus.
My code is like below.

$excel = new COM("excel.application") or die("Unable to instanciate excel");
    $excel->Visible = 0;
    $excel->DisplayAlerts = 0;

    //open  document
    $excel->Workbooks->Open("C:\projects\lab_report_templates\mod\FrSwabCulltureWithQuant.xls");
    $book=$excel->Workbooks(1);

    // Select a sheet
      $sheet=$book->worksheets(1);
      $sheet->activate;                 #Activate it
          
      $cell = $sheet->Cells(7,2) ;  
    $cell->activate;
      $cell->value = report;
....
$excel->Workbooks[1]->SaveAs($file_name);

before it is running ok, not that fast.
But now it looks very slow, even take 1 min to get small report.
sometimes it even get error "Uncaught exception 'com_exception' with message 'Error [0x80010001] Call was rejected by callee"

Anyone can help. Thanks
0
I want to refresh an index.php file every 2 second like cron job do bt cron has limit from 1 minute so is there a way to refresh that file every second in the background ??
0
Hello,

I am trying to write a backup script for my database, it is working pretty good, makes a .sql copy and saves to the server. I would like to save it as a zip archive instead. This is my code to save as .sql (I took out all my zip experiments)

        $now = date("Y-M-d-H");
	$handle = fopen('db-backup-'.$now.'.sql','w+');
	fwrite($handle,$return);
	fclose($handle);

Open in new window

0
We have an app that detects if the device is a smart phone or tablet (vs. computer) and redirects accordingly to the "phone" version of the main page. It does that using this php code:

$loc = "form.php";
if(! empty($_SERVER['HTTP_USER_AGENT'])){
		$useragent = $_SERVER['HTTP_USER_AGENT'];
		if( preg_match('@(iPad|iPod|iPhone|Android|BlackBerry|SymbianOS|SCH-M\d+|Opera Mini|Windows CE|Nokia|SonyEricsson|webOS|PalmOS)@', $useragent) ){
			$loc = "phone.php";
		}
} 
//echo "city tester no = " . $_SESSION['city_tester_no'] . "<br>";
//echo "loc = " . $loc . "<br>";	
header("Location: " . $loc);
exit;

Open in new window


Until recently (last week?) this worked perfectly in all cases (to my knowledge).

Today, for my main customer, it goes to form.php when he accesses it from his iPhone 6.

When I access from my iPhone 6, it behaves in the desired way; goes to phone.php.

Why would this change?

Thanks
0
Hi Guys,

I am having an issue with my server where my server is running really slow, i can see the load avg is pretty high, there is only one site running on it

(http://iradio.ie)

I have attached the error log and the only issue , is where it says empty input file for http://iradio.ie/newPlayer (which does actually exist)

i have changed DNS over the last 24 hours
0

PHP

118K

Solutions

126

Articles & Videos

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.