Ajax Jquery GET PHP aufrufen

02. Dezember 2009

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<HTML>
<HEAD>
<TITLE>Ajax-GET-PHP</TITLE>

<script type=”text/javascript” src=”jquery.js”></script>
<script type=”text/javascript”>
var result;

$(document).ready(function()
{

$(”a.addID”).live(”click”, function(event) {
event.preventDefault();
url = $(this).attr(”href”);
$.get(url,function(data)
{
alert(data);

});

})
});
</script>

</HEAD>

<BODY>
<a class=”addID” href=”ajax.php?id=123″>123</a><br>
<a class=”addID” href=”ajax.php?id=456″>456</a><br>

</BODY>
</HTML>

htaccess und htpasswd mit php erstellen

09. November 2009

Passwortschutz htaccess und htpasswd erzeugen

Dieses PHP-Skript erstellt die htaccess und htpasswd Dateien für den Schutz eines Verzeichnisses bei Apache Webservern. Sie benötigen Schreibrechte in dem Verzeichnis, indem Sie dieses Skript ausführen. (chmod 777)

Keywords: Passwortschutz, Verzeichnis, htaccess, htpasswd, schützen


<?php

# make htaccess and htpasswd

# Lars Brinkmann

# www.webtac.de

function make_htaccess_and_htpasswd ($user, $psw)

{

# get url

$url = $DOCUMENT_ROOT . dirname($_SERVER["PHP_SELF"])
. “/.htpasswd”;

# make .htaccess and .htpasswd

$htaccess_txt = “AuthType Basic” . “\n”;

$htaccess_txt .= “AuthName \”authenticate\”" . “\n”;

$htaccess_txt .= “AuthUserFile $url” . “\n”;

$htaccess_txt .= “require valid-user” . “\n”;

$htpasswd_txt .= “$user:”.crypt($psw,CRYPT_STD_DES).”\n”;

# save files

$htaccess= fopen(”.htaccess”, “w”);

$htpasswd= fopen(”.htpasswd”, “w”);

fputs($htaccess, $htaccess_txt);

fputs($htpasswd, $htpasswd_txt);

fclose($htaccess);

fclose($htpasswd);

}

if (($_POST["user"]) && ($_POST["psw"]))

{

make_htaccess_and_htpasswd ($_POST["user"], $_POST["psw"]);

}

?>

<HTML><HEAD><TITLE> MAKE .htaccess + .htpasswd </TITLE></HEAD>

<BODY>

<FORM METHOD=”POST” ACTION=”<?php echo $_SERVER["PHP_SELF"];?>“>

<p>Username: <INPUT TYPE=”TEXT” NAME=”user”></p>

<p>Passwort: <INPUT TYPE=”TEXT” NAME=”psw”></p>

<p><INPUT TYPE=”submit” VALUE=”make”></p>

</FORM>

</BODY></HTML>

Tschechische Zeichen in FPDF

08. April 2009

Nach diversen Test hier die Lösung für die Ausgabe von tschechischen Zeichen mit FPDF:

  • Mit ttf2pt1 eine .afm Datei erzeigen: ttf2pt.exe -a arial.ttf arialcz
  • Mit makefont arial.cz.z und arialcz.php erstellen

$name = 'arialcz';
include("makefont.php");
MakeFont($name . '.ttf', $name . '.afm','cp1250');

  • Konvertieren der Zeichen

function replace_czech($str)
{
$a["á"] = iconv("UTF-8","CP1250", "á");
$a["é"] = iconv("UTF-8","CP1250", "é");
$a["í"] = iconv("UTF-8","CP1250", "í");
$a["ó"] = iconv("UTF-8","CP1250", "ó");
$a["ú"] = iconv("UTF-8","CP1250", "ú");
$a["š"] = iconv("UTF-8","CP1250", "š");
$a["ť"] = iconv("UTF-8","CP1250", "ť");
$a["ž"] = iconv("UTF-8","CP1250", "ž");
$a["ě"] = iconv("UTF-8","CP1250", "ě");
$a["ď"] = iconv("UTF-8","CP1250", "ď");
$a["ň"] = iconv("UTF-8","CP1250", "ň");
$a["ř"] = iconv("UTF-8","CP1250", "ř");
$a["ů"] = iconv("UTF-8","CP1250", "ů");
$a["č"] = iconv("UTF-8","CP1250", "č");

$a["É"] = iconv("UTF-8","CP1250", "É");
$a["Í"] = iconv("UTF-8","CP1250", "Í");
$a["Ó"] = iconv("UTF-8","CP1250", "Ó");
$a["Ú"] = iconv("UTF-8","CP1250", "Ú");
$a["Á"] = iconv("UTF-8","CP1250", "Á");
$a["Č"] = iconv("UTF-8","CP1250", "Č");
$a["Š"] = iconv("UTF-8","CP1250", "Š");
$a["Ť"] = iconv("UTF-8","CP1250", "Ť");
$a["Ž"] = iconv("UTF-8","CP1250", "Ž");
$a["Ě"] = iconv("UTF-8","CP1250", "Ě");
$a["Ď"] = iconv("UTF-8","CP1250", "Ď");
$a["Ň"] = iconv("UTF-8","CP1250", "Ň");
$a["Ř"] = iconv("UTF-8","CP1250", "Ř");
$a["Ů"] = iconv("UTF-8","CP1250", "Ů");

foreach ($a as $key=&gt;$value)
{
$str = str_replace($key,$value,$str);
}
return $str;
}

PDF mit FDPF erstellen:
$pdf=new PDF();
$pdf-&gt;AddFont('arialcz','','arialcz.php');
$pdf-&gt;SetFont('arialcz');

highlight - suchen und ersetzen

27. März 2009

static function highlight($ausdruck)
{
if (isset($_POST["search"]))
{
$wort = $_POST["search"];

if (is_array($wort))
{
foreach($wort as $key=>$value)
{
$ausdruck = preg_replace(”/((<[^>]*)|(\(’[^']*)|$wort[$key])/ie”,’”\2″||”\3″? stripslashes(”\1″):”\\1“‘, $ausdruck);
}
}
else
{
$ausdruck = preg_replace(”/((<[^>]*)|(\(’[^']*)|$wort)/ie”,’”\2″||”\3″? stripslashes(”\1″):”\\1“‘, $ausdruck);
}
}
return $ausdruck;
}

exec system passthru : Ausführen mit Rückgabe der Ausgabe

12. Februar 2009

# Festplattenkapazität feststellen
$out = “”;
exec(”df -h”,$out);
$out = var_export($out,true);
print $out;

cronjob erstellen / verwalten

13. Januar 2009

Liste: crontab -l
Edit: contab -e

  1. “i” für INSERT-Modus
  2. Änderungen vornehmen
  3. ESC
  4. :x!
  5. fertig

Examples: (Quelle: http://www.monetizers.com/cronjob.php)

# every day at 0:05
5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1

# every first day of the month at 14:15
15 14 1 * * $HOME/bin/monthly

# on weekdays at 22:00
0 22 * * 1-5 mail -s “Adsense UP!” ken%Ken,%%Go buy something!%

Cron jobs help you automate procedures such as backups, executing a file or sending an email. This page is a quick reference for creating a cron entry that defines when a specific application or script should execute.

Type “crontab -e” to edit your cron file. If you just want a listing, use “crontab -l” and if you want to delete a cron job, simply type “crontab -r”.

A line within a cron file will look like this:
1 2 3 4 5 /etc/myScript arguments

There are five numbers at the start of each line and represent the following:
1: minutes (0-59)
2: Hours (0-23)
3: Day (0-31)
4: Month (0-12 or January, February, … 0 and 12=December)
5: Day of the week(0-7 or Monday, Tuesday, Wednesday, … 0 and 7=Sunday)

You can also customize the commands even further, sor example:
*: applies everytime

1-4: start if 1,2,3 or 4 matche
1-4/2 step-by-step, here: 1 and 3
1,5,6: enumeration
*/3: every third
1-4,10-15: enummeration and range combined

To define the SHELL you would like to have execute and who you want to email the results to, use these commands:
SHELL=/bin/bash
MAILTO=myname@myhost

CSV Datei als Downloaddialog öffnen -Header senden

08. Januar 2009

$application=“text/csv”;
header“Content-Type: $application” 
); 
header“Content-Disposition: attachment; filename=$filename”
); 
header“Content-Description: csv File” 
); 
header“Pragma: no-cache” 
); 
header“Expires: 0″ ); 

echo … 

MSSQL Max eines Varchar-Feldes

07. Januar 2009

SELECT MAX (cast([FELD] as int)) FROM [TABELLE]

CSS - Ausblenden beim Drucken

05. November 2008

@media print {
    table.main #navigation {
     display: none;
 }

}

Timestamp DOS YMD Date

05. November 2008

@echo off
set TIMESTAMP=%date:~-4,4%%date:~-7,2%%date:~0,2%
echo %TIMESTAMP%

SCP automatisch übertragen / Kommandozeile winscp

05. November 2008

Wichtig, den Server einmal voher per WinSCP öffnen, so dass der ServerKey gespeichert wird.

Batch-Datei:
C:\Programme\WinSCP\winscp.exe /console /script=C:\SVNWORKING\winscp_transfer_skript.txt
Pause

winscp_transfer_skript.txt:
# Automatically answer all prompts negatively not to stall
# the script on errors
option batch on

# Disable overwrite confirmations that conflict with the previous
option confirm off

# Connect using a password
# open user:password@example.com
# Connect
open username:PASSWORT@IP_or_DNSNAME

# Change the remote directory
cd /export/www/tmp

# Upload the file to current working directory
put C:\tmp\tmp\resources\language.de.php

# Disconnect
close

# Exit WinSCP
exit

mssql Schleife in SQL - Cursor - Stored Procedure

05. November 2008

begin transaction
use DATABASENAME

DECLARE @AppointmentID varchar(36)

DECLARE tblAppointment Cursor FOR
SELECT AppointmentID
FROM partner.appointment

Open tblAppointment
FETCH NEXT FROM tblAppointment
INTO @AppointmentID

WHILE @@FETCH_STATUS = 0
BEGIN

# YOUR CODE
FETCH NEXT FROM tblAppointment INTO @AppointmentID

END

CLOSE tblAppointment
DEALLOCATE tblAppointment

commit transaction

MSSQL Tabelle kopieren

11. September 2008

select * into NEUE-TABELLE from ALTE-TABELLE;

INSERT INTO TAB-NEU(FELD1,FELD2,FELD3)
SELECT Column0,Column1, Column2 FROM TAB-ALT

 

 

UTF8 Umlaute ersetzen SQL + PHP

01. September 2008

CREATE FUNCTION [dbo].[replaceUTF] (@var Varchar(255))
RETURNS varchar(255)
BEGIN
DECLARE @result varchar(255)
SET @Result = REPLACE(@var,'ä','ä')
SET @Result = REPLACE(@Result,'ö','ö')
SET @Result = REPLACE(@Result,'ü','ü')
SET @Result = REPLACE(@Result,'Ä','Ä')
SET @Result = REPLACE(@Result,'Ö','Ö')
SET @Result = REPLACE(@Result,'Ü','Ü')
SET @Result = REPLACE(@Result,'ß','ß')

SET @Result = REPLACE(@var,’ä’,'ä’)
SET @Result = REPLACE(@Result,’ö’,'ö’)
SET @Result = REPLACE(@Result,’ü’,'ü’)
SET @Result = REPLACE(@Result,’Ä’,'Ä’)
SET @Result = REPLACE(@Result,’Ö’,'Ö’)
SET @Result = REPLACE(@Result,’Ü’,'Ü’)
SET @Result = REPLACE(@Result,’ß’,'ß’)

SET @Result = REPLACE(@Result,’é’,'é’)
SET @Result = REPLACE(@Result,’è’,'è’)
SET @Result = REPLACE(@Result,’Ã ‘,’à’)
SET @Result = REPLACE(@Result,’ê’,'ê’)
SET @Result = REPLACE(@Result,’ç’,'ç’)
SET @Result = REPLACE(@Result,’â’,'â’)
SET @Result = REPLACE(@Result,’ë’,'ë’)
SET @Result = REPLACE(@Result,’û’,'û’)

SET @Result = REPLACE(@Result,’ó’,'û’)
RETURN @Result
END

$data=array("complete_name"=&gt;"üdkkÜÄalsß", "name_sort"=&gt;"");
$umlaute = Array("/ä/","/ö/","/ü/","/Ä/","/Ö/","/Ü/","/ß/");
$replace = Array("ae","oe","ue","AE","OE","UE","ss");
$name_neu = preg_replace($umlaute, $replace, $data['complete_name']);
$data['name_sort'] = $name_neu;

ZIP - Files zippen

02. August 2008

Rekurziv: zip -r zipfile.zip datei_oder_ordner

Smarty und Funktionen mit mehreren Parametern z.B. substr

31. Juli 2008

$wert|substr:0:10 (mit Dopplepunkten trennen)

SMARTY und verschachtelte Arrays

31. Juli 2008

$data["abc"]["def"]…

in Smarty: $data.abc.def

MySQL Dumb von der Console importieren

30. Juli 2008

mysqldump -uroot -pmeinpasswort datenbank > /tmp/dump.sql

Oft benötigte DATUMS-SQL-Befehle

24. Juli 2008

http://www.ms-office-forum.net/forum/showthread.php?t=187265

SQL - Doppelte Einträge in einer Tabelle anzeigen

19. Juli 2008

SELECT [feld] FROM [table] GROUP BY [feld] HAVING count([feld]) > 1

Statische Methoden einer Klasse in Smarty aufrufen

29. Juni 2008

Methode registrieren:

# array($class, $method)
$t->register_modifier(’name’, array(”mandator”, “getName”));

Diese kann dann als Modifier für eine Variabel benutzen, also z.B. die MandatorID:

{$data[key]->mandatorID|name}

Somit wird $data[key]->mandatorID an den Modifier name, welches die statische Methode von mandator::getName ist, übergeben und ausgeführt.

http://www.smarty.net/manual/en/api.register.modifier.php

The php-function callback function can be either:

  • A string containing the function name
  • An array of the form array(&$object, $method) with &$object being a reference to an object and $method being a string containing the method-name
  • An array of the form array($class, $method) with $class being the class name and $method being a method of the class.

access_log Apache Logfilekonfiguration

19. Juni 2008

LogFormat “%h %l %u %t \”%r\” %>s %b %v %U” common

%v = Server

/etc/httpd/httpd.conf
CustomLog /var/log/httpd/access_log common

mod_rewrite aktivieren

08. Juni 2008

/etc/apache2/sysconfig.d/loadmodule.conf

LoadModule rewrite_module /usr/lib/apache2-prefork/mod_rewrite.so

apache2ctl restart

Gute Seite zu mod_rewrite

08. Juni 2008

http://www.modrewrite.de/foren/ftopic82.html

MySQLTimestamp2Date

07. Juni 2008
function MySQLTimestamp2Date($timestamp)
{
	// 0000-00-00 00:00:00
	$Y = substr($timestamp,0,4);
	$m = substr($timestamp,5,2);
	$d = substr($timestamp,8,2);
	$H = substr($timestamp,11,2);
	$i = substr($timestamp,14,2);

	return "$d.$m.$Y $H:$i";
}

Tabellenzeilen mit unterschiedlicher Hintergrundfarbe

07. Juni 2008
$color = 1;
while(...)
{
  if ($color % 2 == 0)
  {
    echo '<tr>';
  }
  else
  {
    echo '<tr bgcolor="EEEEEE">';
  }
  ...
  $color++;
}

Letztes Zeichen eines Strings entfernen

07. Juni 2008

$value = substr($value,0,(strlen($value)-1));

Doppelte Leerzeichen entfernen

07. Juni 2008

private static string RemoveDoubleSpaceCharacters(string text)
{
return System.Text.RegularExpressions.Regex.Replace(text, "[ ]+", " ");
}

stripHtml

07. Juni 2008

private static string StripHTML(string inputString)
{
return Regex.Replace(inputString, "<.*?>", string.Empty);
}

Datei speichern + String anhängen

07. Juni 2008

public static void Append(string sFilename, string sLines)
{
StreamWriter myFile = new StreamWriter(sFilename, true, System.Text.Encoding.Default);
myFile.Write(sLines);
myFile.Close();
}

Datei speichern

07. Juni 2008

public static void WriteFile(String sFilename, String sLines)
{
StreamWriter myFile = new StreamWriter(sFilename);
myFile.Write(sLines);
myFile.Close();
}

IsValidAlphaNumericString

07. Juni 2008

public static bool IsValidAlphaNumericString(string strAlphanum)
{
System.Text.RegularExpressions.Regex pattern = new System.Text.RegularExpressions.Regex(@"^[A-Za-z0-9]+$");
return pattern.IsMatch(strAlphanum.Trim());
}

Email prüfen

07. Juni 2008

public static bool IsEmail(string text)
{
return System.Text.RegularExpressions.Regex.IsMatch(text, @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
}

Monitoring http und mail

07. Juni 2008

tail -f /var/log/httpd/access_log
tail -f /var/log/mail

ps aux | grep httpd

iptraf

top
(Shift P, Shift M um zu sortieren)

Wie stelle ich unter Plesk safe_mode und open_basedir um

07. Juni 2008

1.) Also vhost.conf anlegen

<Directory /var/www/vhosts/domain.de/httpdocs>
  <IfModule mod_php5.c>
    php_admin_flag engine on
    php_admin_flag safe_mode off
    php_admin_value open_basedir “/var/www/vhosts/domain.de/httpdocs:/usr/share/php”
  </IfModule>
</Directory>

2.) Mit folgendem Befehl die httdp.include neu erzeugen
/usr/local/psa/admin/sbin/websrvmng –reconfigure-vhost –vhost-name=domain.de

3.) Apache2 neu starten
/etc/init.d/apache2 restart

MySQL - Pfad und Version

07. Juni 2008

Pfad zu den MySQL-Datenbanken:
/var/lib/mysql/

Konfigurationsdaten anzeigen:
mysqld –verbose –help