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

1258 views

Check if service is running

Written by leif. Posted in Dos, Programmering

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
sc query "%~1"|findstr "STATE.*:.*4.*RUNNING" >NUL
IF ERRORLEVEL 1 (
ECHO service %1 is stopped
goto :end
)
echo Service %1 is running
:end
EXIT /b
1173 views

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
)
:continue

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

:week
echo Det er weekend

:end

1015 views

Batch. ping scanner

Written by leif. Posted in Dos, Programmering, Tips

@ECHO OFF
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
)
GOTO :EOF

:ping
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

 

1147 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

1265 views

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


$('#top').children(':first-child').next().whatever();

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


$($('#top').children()[1]).whatever();

550 views