$_SERVER[‘PATH_INFO’] not working!

Written by leif. Posted in PHP, Programmering

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>";
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
    [HTTP_HOST] => localhost:8080
    [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
    [HTTP_CONNECTION] => keep-alive

fpdf – tabel-cells example

Written by r2d2. Posted in PHP, Programmering


$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->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);

Check if service is running

Written by r2d2. Posted in Dos, Programmering

@echo off
sc query "%~1"|findstr "STATE.*:.*4.*RUNNING" >NUL
ECHO service %1 is stopped
goto :end
echo Service %1 is running

Batch script, find hverdag og weekend

Written by leif. Posted in Dos, Programmering

@echo off

FOR /F "skip=1" %%A IN ('WMIC Path Win32_LocalTime Get DayOfWeek' ) DO (
set DOW=%%A
goto :continue

if %DOW% EQU 0 goto :week
if %DOW% EQU 6 goto :week
echo Det er hverdag
goto :end

echo Det er weekend


Batch. ping scanner

Written by leif. Posted in Dos, Programmering, Tips

SET output=%USERPROFILE%\output.txt
IF EXIST “%output%” DEL “%output%”
FOR /L %%G IN (1, 1, 69) DO (
CALL :ping 192.168.%%G.3
CALL :ping 192.168.%%G.4

ping -n 1 %1 >NUL && ECHO %1>>”%output%”


source: http://stackoverflow.com/questions/5037382/batch-file-loop-ping-output-to-file-hosts-that-are-up



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

Getting the 2nd child element

Written by leif. Posted in Javascript, Programmering, Tips

A number of ways to do this one. I’m going to assume the toplevel div has an id of ‘top’. This is probably the best one:

$('#top > :nth-child(2)').whatever();



or if you know for a fact there are at least 2 children