Move WFV

Written by r2d2. Posted in PHP, Tips, Wordpress

Transfer WP file version to an other site?

You will need to recalculate the data location length.

Here is a quick made converter.

<?php

/*
Hvis WFV (WP file version) SQL-data skal flyttes til anden webside, kræves det en genberegning af direktorie+fil længe. 

a:4:{s:4:"size";s:6:"2.05Mb";s:4:"path";s:75:"/var/www/htdocs/public_html/noah.crysberg.dk/wp-content/wfv_files/Certifikater.pdf";s:4:"name";s:16:"Certifikater.pdf";s:4:"type";s:3:"pdf";}
                                          ~~  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Input: filename.sql
Output: NEW-filname.sql
*/

$filename="wp_wfv_files.sql";

$reg='|.*path\\\";s:([0-9]{1,3}):(\\\".*?\\\")|i';

if ($file = fopen($filename, "r")) {
	while(!feof($file)) $a[] = fgets($file);
	fclose($file);
}



$file = fopen("NEW-".$filename, "w");
foreach ($a as $key => $line) { 
	$line = preg_replace_callback(
		$reg,
		function ($matches) {
			return str_replace( 'path\\";s:'.$matches[1], 'path";s:'.(strlen($matches[2])-4), $matches[0]);
		},
		$line
	);
	fwrite($file, $line);
//	echo $line;    	
}
fclose($file);
		
?>

 

51 views

$_SERVER[‘PATH_INFO’] not working!

Written by leif. Posted in PHP, Programmering

<?php
if (isset($_SERVER['PATH_INFO'])) {
    $request_uri = trim($_SERVER['PATH_INFO'], '/');
} elseif (isset($_SERVER['ORIG_PATH_INFO'])) {
    $request_uri = trim(str_replace($_SERVER['SCRIPT_NAME'], '', $_SERVER['ORIG_PATH_INFO']), '/');
} else {
    $request_uri = '';
}


echo "PATH_INFO = " . $_SERVER['PATH_INFO'] . "<br>"; 
echo "\$request_uri = ".$request_uri . "<br>";
echo "All server vars<br>";
echo "<pre>";
print_r($_SERVER);
echo "</pre>";
echo "tested with: http://localhost:8080/wordpress/leif.php/asd/qwe<br>";
echo "Output:<pre>";
echo "

PATH_INFO = /asd/qwe
$request_uri = asd/qwe
All server vars
Array
(
    [HTTP_HOST] => localhost:8080
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    [HTTP_CONNECTION] => keep-alive
1184 views

How to ‘insert if not exists’ in MySQL?

Written by leif. Posted in Mysql, PHP, Tips

see http://bogdan.org.ua/2007/10/18/mysql-insert-if-not-exists-syntax.html

there’s also INSERT … ON DUPLICATE KEY UPDATE syntax, you can find explanations on dev.mysql.com


Post from bogdan.org.ua
18th October 2007

To start: as of the latest MySQL, syntax presented in the title is not possible. But there are several very easy ways to accomplish what is expected using existing functionality.

There are 3 possible solutions: using INSERT IGNORE, REPLACE, or INSERT … ON DUPLICATE KEY UPDATE.Imagine we have a table:

CREATE TABLE `transcripts` (
1643 views

fpdf – tabel-cells example

Written by leif. Posted in PHP, Programmering

$pdf->SetX(5);

$pdf->Cell(40,5,'[ x ] checkbox1′,1,0,’L’,0);
$pdf->Cell(40,5,'[ x ] checkbox2′,1,0,’L’,0);
$pdf->Cell(40,5,'[ x ] checkbox3′,1,0,’L’,0);

$pdf->Ln();
$pdf->SetX(5);

$pdf->Cell(40,5,'[ x ] checkbox4′,1,0,’L’,0);
$pdf->Cell(40,5,'[ x ] checkbox5′,1,0,’L’,0);
$pdf->Cell(40,5,'[ x ] checkbox6′,1,0,’L’,0);

1288 views

PHP_SELF

Written by leif. Posted in PHP, Programmering

Do not use any of the suggested versions of PHP_SELF. It is a security nightmare, opening up your PHP to a multitude of possible injection attacks.

What are you trying to achieve? Generate the URL for a form sending to itself? Use action=”” for that – it is a valid approach and will always use the URL for sending the form as for loading.

If you must know the requested script, use $_SERVER[‘SCRIPT_NAME’] instead.

Or $_SERVER[‘PHP_SELF’], not $PHP_SELF. See the docs

1296 views