php 1×1 pixel image

September 27th, 2006 by admin

wer in php ein mini images benötigt das 1x1 pixel groß und weiß bzw. leer ist.

hier ist die funktion.

PHP:
  1. function mini_image()
  2. {
  3. header("Content-Type: image/jpg");
  4. header("Content-Length: 631");
  5. echo base64_decode('/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQND
  6. AsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBg
  7. NDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/w
  8. AARCAABAAEDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgE
  9. DAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJ
  10. icoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5i
  11. ZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/
  12. 8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxE
  13. EBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHS
  14. ElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba
  15. 3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD3+iiig
  16. D//2Q==');
  17. }

Posted in coding, php | No Comments »

scuttle with visitcounter and “secure� redirect part2

September 25th, 2006 by admin

i forgot an really important file: redirect.php for scuttle

just extract the file in the scuttle folder. the file calls the scuttle redirector template. without the redirect.php you will get an 404 error.

another small bug is in the rrs-feed. just copy my rss.php for scuttle to your scuttle directory and your rss-feeds will work also.

Posted in coding, php | 3 Comments »

octal “encryption” in php

September 24th, 2006 by admin

in der php dokumentation kann man nachlesen das es viele wege gibt ein string darzustellen.

unter anderem ist dort auch die octale schreibweise aufgeführt.

wenn man nun alle ausgabe in octal codiert sieht der user nur noch strings wie diesen "\147\145\164\105\154\145\155\145\156\164\102".

einige scriptentwickler in php benutzen diese schreibweise um das script zu verschlüßeln und unleserlich zu halten. problem gibt es dann wenn ein script nicht richtig funktioniert oder fehler ausgibt. für diesen fall hab ich mal ein kleinen satz an funktionen geschrieben.

die funktionen codieren und decodieren den strings in die octal schreibweise.

PHP:
  1. function string2oct_str($string)
  2. {
  3. $base = 8;
  4. for ($i=0;$i <strlen($string);$i++)
  5. {
  6. $ascii = ord($string[$i]);
  7. $oct_string .= '\\'.base_convert($ascii, 10, 8);
  8. }
  9. return $oct_string;
  10. }
  11.  
  12. function oct2char($oct)
  13. {
  14. return chr(base_convert($oct[1], 8, 10));
  15. }
  16.  
  17. function octstring2string($oct_string)
  18. {
  19. //regex -> \[0-7]{1,3} = oct
  20. return(preg_replace_callback("/\\\([0-7]{1,3})/i",'oct2char',$oct_string));
  21. }
  22.  
  23. //aufruf
  24.  
  25. echo octstring2string('\147\145\164\105\154\145\155\145\156\164\102');
  26. echo string2oct_str('getElementB');

da ein script meist aus viele dateien besteht hab ich noch eine funktion die rekursiv ordner scannt und alle strings von octal in "normale" schreibweise umwandelt

PHP:
  1. function dirTree($dir) {
  2. $d = dir($dir);
  3. if($d == false)
  4. die('nix dir');
  5. while (false !== ($entry = $d->read())) {
  6. if($entry != '.' && $entry != '..' && !is_dir($dir.$entry)&& substr($entry,-4)=='.php')
  7. {
  8. echo('decode->'.$entry."\n");
  9. $filename = $dir.$entry;
  10. $file_content = file_get_contents($filename);
  11. if($file_content == false)
  12. die('fehler');
  13. $file_content = octstring2string($file_content);
  14. if(file_put_contents($filename, $file_content)==0)
  15. die('es wurden 0 bytes geschrieben.');
  16. }
  17. }
  18. $d->close();
  19. return $arDir;
  20. }
  21.  
  22. //aufruf
  23. print_r(dirTree('/srv/www/htdocs-default_16/script/'));

Posted in coding, php | No Comments »

scuttle with visitcounter and “secure” redirect

September 23rd, 2006 by admin

scuttle is a nice social bookmark tool. you can compare scuttle to the famous del.icio.us.

the current version 0.7.2 has many features but there is no counter that counts your bookmark visits.

i will instruct you how to create a working counter for your bookmarks and tell you how to "secure"(without the nasty referer) redirect to the url.

so lets start.

1. we need a template that redirect us to the url (without any trace). just copy the scuttle redirector in you "templates" folder.

2. we need to edit the "bookmarks.tpl.php" (also in the "templates" folder).

just replace the file with this bookmarks.tpl.php

3. now we edit the "bookmarkservice.php" file wich is located in the "services" directory in your scuttle forder.

search for

PHP:
  1. function & getBookmarks($start = 0, $perpage = NULL, $user = NULL, $tags = NULL, $terms = NULL, $sortOrder = NULL, $watched = NULL, $startdate = NULL, $enddate = NULL, $hash = NULL) {

and insert ABOVE

PHP:
  1. //macosmod
  2. function updateBookmarkCounter($bId, $visits) {
  3. if (!is_numeric($bId) || !is_numeric($visits))
  4. return false;
  5. $updates = array('visits' => $visits+1);
  6. $sql = 'UPDATE '. $GLOBALS['tableprefix'] .'bookmarks SET '. $this->db->sql_build_array('UPDATE', $updates) .' WHERE bId = '. intval($bId);
  7. $this->db->sql_transaction('begin');
  8. if (!($dbresult = & $this->db->sql_query($sql))) {
  9. $this->db->sql_transaction('rollback');
  10. message_die(GENERAL_ERROR, 'Could not update bookmark', '', __LINE__, __FILE__, $sql, $this->db);
  11. return false;
  12. }
  13. $this->db->sql_transaction('commit');
  14. return true;
  15. }
  16. //macosmod

now search for

PHP:
  1. default:
  2. $query_5 = ' ORDER BY B.bDatetime DESC ';

and insert ABOVE

PHP:
  1. //macosmod
  2. case 'visits_desc':
  3. $query_5 = ' ORDER BY B.visits DESC ';
  4. break;
  5. case 'visits_asc':
  6. $query_5 = ' ORDER BY B.visits ASC ';
  7. break;
  8. //macosmod

4. mysql needs an field that counts our visits, so go to your mysql admin (eg. phpmyadmin), select your scuttle database and execute the following sql code

CODE:
  1. ALTER TABLE `sc_bookmarks` ADD `visits` INT NOT NULL AFTER `bHash`

5. activate the redirector. go to your "config.inc.php" and set the following values

CODE:
  1. $useredir = true;
  2.  
  3. $url_redir = 'visit_counter';

thats it. now our scuttle counts the hits and redirect us to the url in a "secure" way.

Posted in coding, php | 3 Comments »

source rpm installieren

September 13th, 2006 by admin

ihr habt eine *.src.rpm und habt keine ahnung wie ihr die installiert bzw. compiliert bekommt.

CODE:
  1. rpmbuild --rebuild NAME_DER_RPM .scr.rpm

das ganze sollte die source rpm für euer system compilieren und bei den rpm files abspeichern.

wo winde ich das compilierte rpm file? einfach mal im root suchen da jede distri. die dateien an verschiedenen orten speichert.

CODE:
  1. find -name *NAME_DER_RPM*

bei suse finden wir das ganze in /usr/src/packages/RPMS/ARCH/NAME_DER_RPM.rpm

Posted in misc | No Comments »