I need php code for Back Button

Discussion in 'PHP' started by nals, Dec 2, 2007.

  1. #1
    Can someone please tell me the php code.
    Simple <back> button (link to back page or given web address>

    Thanks
    :confused:
     
    nals, Dec 2, 2007 IP
  2. Jackel.ca

    Jackel.ca Well-Known Member

    Messages:
    108
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    128
    #2
    You could use..

    
    echo "<a href=\"" . $_SERVER['HTTP_REFERER'] . "\">Back</a>";
    
    PHP:
    Not always reliable though.
     
    Jackel.ca, Dec 2, 2007 IP
  3. BuildHome

    BuildHome Well-Known Member

    Messages:
    837
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    108
    #3
    Why in PHP? You can do it in JavaScript:

     
    BuildHome, Dec 2, 2007 IP
  4. nals

    nals Peon

    Messages:
    168
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    <?php
    
    require_once("config.php");
    
    // path being dynamically requested
    if(!empty($_REQUEST['src'])) {
        if(file_exists(stripslashes(PATH.$_REQUEST['src'])))
            $src = urldecode(stripslashes(PATH.$_REQUEST['src']));
        else
            $src = null;
            
        // extra validation
        $src = stristr($src, '..') ? null : $src;
    }
    
    // see if we're working with a thumbnail or not
    $size = !empty($_REQUEST['size']) && $_REQUEST['size'] == 'full' ? $_REQUEST['size'] : null;
    
    // draw watermarked & thumbnail images
    function draw_image($src) {
        global $size;
        list($width, $height, $type, $attr) = getimagesize($src);
        $img = imagecreatefromstring(file_get_contents($src));
    
        if($size == 'full') {
            $red = imagecolorallocate($img, 0xFF, 0x00, 0x00);
            imagestring($img, 5, 3, 3, WATERMARK, $red);
        } else {
            $lowest = min(THMBWIDTH / $width, THMBHEIGHT / $height);
            if($lowest < 1) {
                $smallwidth = floor($lowest*$width);
                $smallheight = floor($lowest*$height);
                $tmp = imagecreatetruecolor($smallwidth, $smallheight);
                imagecopyresized($tmp, $img, 0, 0, 0, 0, $smallwidth, $smallheight, $width, $height);
                imagedestroy($img);
                $img = $tmp;
            }
        }
        
        switch($type) {
            case 1:
            header("Content-type: image/gif");
            imagegif($img);
            break;
    
            case 2:
            header('Content-Type: image/jpeg');
            imagejpeg($img, '', 100);
            break;
    
            case 3:
            header("Content-type: image/png");
            imagepng($img);
            break;
        }
        imagedestroy($img);
    }
    
    if(!empty($src)) {
        draw_image($src);
    } else {
        header("Content-type: image/png");
        $img = imagecreatetruecolor(THMBWIDTH, THMBHEIGHT);
        $black = imagecolorallocate($img, 0x00, 0x00, 0x00);
        $white = imagecolorallocate($img, 0xFF, 0xFF, 0xFF);
        imagestring($img, 5, 3, 3,  "NO IMAGE", $white);
        imagepng($img);
        imagedestroy($img);
    }
    
    
    ?>
    
    PHP:
     
    nals, Dec 2, 2007 IP
  5. nals

    nals Peon

    Messages:
    168
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I have tried both , php and javascript but not working
     
    nals, Dec 2, 2007 IP
  6. sharry

    sharry Peon

    Messages:
    319
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #6
    i usually follow this method and it works fine
     
    sharry, Dec 3, 2007 IP