php.de

Zurück   php.de > Webentwicklung > PHP Einsteiger > PHP Tipps 2005

 
 
LinkBack Themen-Optionen Thema bewerten
Alt 04.05.2005, 10:17  
Gast
 
Beiträge: n/a
Standard

wo und wie muss ich hier die session einbauen ??

PHP-Code:
<?php

/* ------------------------- CONFIGURATION -----------------------
    Set $folder to the full path to the location of your images.
    For example: $folder = '/user/me/example.com/images/';
    If the rotate.php file will be in the same folder as your
    images then you should leave it set to $folder = '.';
*/
    
$folder '.';
/*    
    Most users can safely ignore this part.  If you're a programmer,
    keep reading, if not, you're done.  Go get some coffee.

    If you'd like to enable additional image types other than
    gif, jpg, and png, add a duplicate line to the section below
    for the new image type.
    
    Add the new file-type, single-quoted, inside brackets.
    
    Add the mime-type to be sent to the browser, also single-quoted,
    after the equal sign.
    
    For example:
    
    PDF Files:

        $extList['pdf'] = 'application/pdf';
    
    CSS Files:

        $extList['css'] = 'text/css';

    You can even serve up random HTML files:

        $extList['html'] = 'text/html';
        $extList['htm'] = 'text/html';

    Just be sure your mime-type definition is correct!

*/

    
$extList = array();
    
$extList['gif'] = 'image/gif';
    
$extList['jpg'] = 'image/jpeg';
    
$extList['jpeg'] = 'image/jpeg';
    
$extList['png'] = 'image/png';
    

// You don't need to edit anything after this point.


// --------------------- END CONFIGURATION -----------------------

$img null;

if (
substr($folder,-1) != '/') {
    
$folder $folder.'/';
}

if (isset(
$_GET['img'])) {
    
$imageInfo pathinfo($_GET['img']);
    if (
        isset( 
$extListstrtolower$imageInfo['extension'] ) ] ) &&
        
file_exists$folder.$imageInfo['basename'] )
    ) {
        
$img $folder.$imageInfo['basename'];
    }
} else {
    
$fileList = array();
    
$handle opendir($folder);
    while ( 
false !== ( $file readdir($handle) ) ) {
        
$file_info pathinfo($file);
        if (
            isset( 
$extListstrtolower$file_info['extension'] ) ] )
        ) {
            
$fileList[] = $file;
        }
    }
    
closedir($handle);

    if (
count($fileList) > 0) {
        
$imageNumber time() % count($fileList);
        
$img $folder.$fileList[$imageNumber];
    }
}

if (
$img!=null) {
    
$imageInfo pathinfo($img);
    
$contentType 'Content-type: '.$extList$imageInfo['extension'] ];
    
header ($contentType);
    
readfile($img);
} else {
    if ( 
function_exists('imagecreate') ) {
        
header ("Content-type: image/png");
        
$im = @imagecreate (100100)
            or die (
"Cannot initialize new GD image stream");
        
$background_color imagecolorallocate ($im255255255);
        
$text_color imagecolorallocate ($im0,0,0);
        
imagestring ($im255,  "IMAGE ERROR"$text_color);
        
imagepng ($im);
        
imagedestroy($im);
    }
}

?>
 
Sponsor Mitteilung
PHP Code Flüsterer

Registriert seit: 21.08.2005
Beiträge: 4682
PHP-Kenntnisse:
Fortgeschritten

Alt 04.05.2005, 10:29  
Gast
 
Beiträge: n/a
Standard

Soviel ich bis jetzt gelernt habe, muss session_start(); ganz nach oben !
Dann kannst du auf die Sessionvariablen zugreifen und verändern !
 
Alt 04.05.2005, 10:38  
Gast
 
Beiträge: n/a
Standard

An den Anfang die Zeile

session_start();

einbauen, dann dies umbauen (ungetestet!!!)
PHP-Code:
<?
if (isset($_GET['img']) || isset($_SESSION['img'])) { // Zeile erweitert
   // Die nächsten 4 Zeilen rein
   
if (isset($_SESSION['img']))
     
$name $_SESSION['img'];
   else
     
$name $_GET['img'];

   
$imageInfo pathinfo($name); // Hier geändert
   
if (
       isset( 
$extListstrtolower$imageInfo['extension'] ) ] ) &&
        
file_exists$folder.$imageInfo['basename'] )
    ) {
      
$img $folder.$imageInfo['basename'];
   }
}
?>
Und noch hier:
PHP-Code:
<?
if ($img!=null) {
   
$_SESSION['img'] = $img// Diese Zeile rein
   
$imageInfo pathinfo($img);
   
$contentType 'Content-type: '.$extList$imageInfo['extension'] ];
   
header ($contentType);
   
readfile($img);
} else { 
?>
Gruß
phpfan
 
Alt 04.05.2005, 12:08  
Gast
 
Beiträge: n/a
Standard

nochmals ich
ich pack das irgendwie nicht ...

hab hier ein anderes sehr einfaches randomscript gefunden :

PHP-Code:
<?php

/*
 * Name your images 1.jpg, 2.jpg etc.
 *
 * Add this line to your page where you want the images to 
 * appear: <?php include "random.php"; ?>
 */ 

// Change this to the total number of images in the folder
$total "6";

// Change to the type of files to use eg. .jpg or .gif
$file_type ".jpg";

// Change to the location of the folder containing the images
$image_folder "./img";

// You do not need to edit below this line

$start "1";

$random mt_rand($start$total);

$image_name $random $file_type;

echo 
"<img src=\"$image_folder/$image_name\" alt=\"$image_name\" />";
?>
dieses hab ich nun per include in die seite1.php eingebunden.

PHP-Code:
<?php
session_start
(); 
include 
"random.php";
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Unbenanntes Dokument</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>



[url="seite2.php"]seite 2[/url]</p>


[url="seite3.php"]seite 3[/url]</p>
</body>
</html>
beim aufrauf der seite1.php wird nun einzufälliges bild vom ordner img geholt. beim link auf seite2.php oder seite 3.php sollte dieses übergeben werden.
Wie binde ich den dieses bild nun ein ?
 
Alt 04.05.2005, 12:21  
Gast
 
Beiträge: n/a
Standard

Und dann findest du noch ein Script und möchtest das dann geändert haben, weil du es wiedr nicht verstehst, oder? Glaubst du wirklich, wir hätten nichts besseres zu tun? Ganz ehrlich, das finde ich langsam dreist. Lerne PHP, dann kannst du das alleine.

Gruß
phpfan
 
 


Themen-Optionen
Thema bewerten
Thema bewerten:

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an
Gehe zu

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
Sessions und Logins Faebe PHP Tipps 2008 1 29.10.2007 09:04
Sessions, wie funktioniert das eigentlich genau? tinchen PHP Tipps 2008 7 08.10.2007 15:06
2 Sessions Kein Genie PHP Tipps 2006 8 21.07.2006 15:45
[Erledigt] probleme mit sessions PHP Tipps 2007 1 17.11.2005 10:43
Nach Einfügugng der Sessions funktioniert mein Program nicht PHP-Fortgeschrittene 1 02.10.2005 06:13
Module im Eingenbau die 2te (SESSIONS and Security) ChewyF5 PHP-Fortgeschrittene 8 05.08.2005 11:16
Sessions! DER_Brain PHP Tipps 2005-2 5 30.06.2005 14:51
2 Sessions? PHP Tipps 2005 5 29.04.2005 19:04
[Erledigt] [PHP5 / W2k3 / IIS] Sessions funktionieren nicht PHP-Fortgeschrittene 2 02.04.2005 00:39
fenster nicht ohne sessions gelöscht zu haben schlie. lassen PHP Tipps 2005 1 14.02.2005 21:16
Proble mit Sessions PHP Tipps 2005 7 07.02.2005 17:42
Sessions werden automatisch an Links angehängt PHP-Fortgeschrittene 3 10.12.2004 13:50
Sessions auf Apache2 gehen nicht! Server, Hosting und Workstations 1 27.09.2004 17:39
[Erledigt] Usermanagement mit Sessions - Sicherheitsprobleme ? PHP Tipps 2004 0 30.06.2004 09:49
Sessions, sessions und nochmal sessions PHP-Fortgeschrittene 0 06.06.2004 00:36

Besucher kamen über folgende Suchanfragen bei Google auf diese Seite
content-type: image/jpeg session

Alle Zeitangaben in WEZ +2. Es ist jetzt 12:32 Uhr.




Powered by vBulletin® Version 3.7.2 (Deutsch)
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Aprilia-Forum, Aquaristik-Forum, Liebeskummer-Forum, Zierfisch-Forum, Geizkragen-Forum

Creative Commons License
Dieser Inhalt ist unter einer Creative Commons-Lizenz lizenziert.