storeing php url variables as a php variable

Discussion in 'Web Design and Development' started by hansolo669, Feb 14, 2012.

  1. hansolo669 macrumors regular

    Joined:
    Oct 5, 2009
    #1
    i have searched around to no avail. essentially what i want to do is have the url variable (?1 ?234 ?2534753 what ever it is) store itself in a php variable which would then inject itself into an html image tag loading the image with the corresponding number (i.e "www.image.com?1" would load "1.jpg" into the page)

    my code (for this part) as it stands looks like this
    Code:
    <? if (!empty($_SERVER["QUERY_STRING"])) ?>
    <? $img_name = QUERY_STRING ?>
    <img src= "<? echo $img_name ?>" width="1024" height="768"/>
    
     
  2. Darth.Titan macrumors 68030

    Darth.Titan

    Joined:
    Oct 31, 2007
    Location:
    Austin, TX
    #2
    I believe the route I'd take would be more like:
    PHP:
    <?php
    $img_path 
    'images/';
    if (isset(
    $_GET['image'])){
        
    $img_name $img_path $_GET['image'];
        list(
    $width$height$type$attr) = getimagesize($img_path.'image_name.jpg');
    }
    ?>
    <img src= "<?=$img_name?><?=$attr?> />
    (i.e "www.image.com?image=1.jpg" would load "1.jpg" into the page)

    Of course that would need to be tweaked depending on your image directory location.
     

Share This Page