Jump to content

Help Please! this was working but no longer! $PHP_SELF


Go to solution Solved by micky1955,

Recommended Posts

Hi all,

 

help needed please.

our site is http://www.1stwestpont.org.uk/photo_gallery3.php

 

i am using the below code to display a menu of image directories stored on the server.

on choosing an option it should ( and it used to! ) give the url for another bit of code to display the images.

the directory names are stored in the array $darr[ ] having read the image directory.

 

$lmen is just the number of directories.

 

the variable $dirchoice is used to pass the value chosen to the display code but doesn't seem to be passed anymore.

 

is this something to do with a newer version of PHP on my server perhaps?

 

our site is http://www.1stwestpont.org.uk/photo_gallery3.php.

 

i hope someboy can help me - this was my first foray into PHP and the code may not be the best but and as i said before, it used to work!!

 

yours hopefully,,

Micky

<ul>
<?php
	for ($x=0; $x<$lmen; $x++)
	{
		?>
		<li><a href=<?php echo("$PHP_SELF?dirchoice=" . $darr[$x]) ?> ><?php echo(str_replace("_"," ",$darr[$x])); ?></a></li>
		<?php
	}
	?>
</ul>

Have you tried switching to $_SERVER['PHP_SELF']?

 

 

Side note: I would recommend staying away from PHP_SELF in this scenario for security reasons. More information can be found here:

http://www.cyberscorpion.com/2012-03/why-php_self-should-be-avoided-when-creating-website-links/

 

The alternative would be to just use the page name.

<li><a href=<?php echo("photo_gallery3.php?dirchoice=...

If you really need to use PHP_SELF, you should look into sanitizing what the variable contains.

Hi trq,

 

thanks for looking at my problem.

 

i've tried what you suggested (<a href="?dirchoice=<?php echo $darr[$x]; ?>">) with no luck.

 

the directory name is not being stored in the variable $dirchoice.

 

this bit is in photo_galley3.php and includes show_pics.php which i've shown below.

if (isset($dirchoice))
{    
    echo("dirchoice set");
    $small_pic_dir = $dirchoice . "/" ."tns/";
    /* $full_dir stores becomes chosen dir name plus thumbnail */
    $full_dir="/home/ddm993c/public_html/1stwest/images/" . $small_pic_dir;
       $count = 1;
    $mydir = dir($full_dir);
    ?>
    <span class="text12"><p style="color:#CC0000"><?php echo(str_replace("_"," ",$dirchoice)); ?></p></span>
    <?php

    include ("show_pics.php");
    
       echo "</table>";
       $mydir->close();
}    
else
{
    echo("dirchoice not set");
    $dirchoice = "Big_Pit";
    $count = 1;
    $small_pic_dir = $dirchoice . "/" ."tns/";
    $full_dir="/home/ddm993c/public_html/1stwest/images/" . $small_pic_dir;
    $mydir = dir($full_dir);
    ?>
    <span class="text12"><p style="color:#CC0000"><?php echo(str_replace("_"," ",$dirchoice)); ?></p></span>
    <?php
      include ("show_pics.php");
    echo "</table>";
      $mydir->close();

}

THIS IS show_pics.php:

<?php
while(($file = $mydir->read()) !== false)
    {
      if ($file !== "." && $file !== "..")
        {
        if ($count == 1)
            {
                $count++;
                $fstring = substr("$file", 0, -4);
                $smallpic =  $small_pic_dir . "$file";
                $smallpic = "images/" . $smallpic;
                $largepic = $large_pic_dir . "$file";
                echo ("<table border=0 cellpadding=0 cellspacing=10 style=bordercolor=#111111 width=100%>
                <tr>
                    <td width=25% align=center>");
                    ?>
                        <img src="<?php echo($smallpic); ?> "width=240 height=172 />
                        <?php echo($fstring);?>
                    </td>
                    <?php
            }
            elseif ($count == 2)
            {
                $fstring = substr("$file", 0, -4);
                $smallpic = "$small_pic_dir" . "$file";
                $smallpic = "images/" . $smallpic;
                
                $largepic = "$large_pic_dir" . "$file";
                echo ("<td width=25% align=center>");
                    ?>
                    <img src="<?php echo($smallpic); ?> "width=240 height=172 />
                    <?php echo($fstring);?>
                    </td>
                    <?php
                $count++;
            }
            elseif ($count == 3)
            {
                $fstring = substr("$file", 0, -4);
                $smallpic = "$small_pic_dir" . "$file";
                $smallpic = "images/" . $smallpic;
                $largepic = "$large_pic_dir" . "$file";
                echo ("<td width=25% align=center>");
                ?>
                    <img src="<?php echo($smallpic); ?> "width=240 height=172 />
                    <?php echo($fstring);?>
                    </td>
                    <?php
                $count = 1;
            } //end if ($count == 1)
          }  // END if ($file !== "." && $file !== "..")
    }  // END while(($file = $mydir->read()) !== false)
?>
  • Solution

hi cyberRobot,

thanks for looking at my problem.

 

i see what you mean about $php_self and will stop using it altogether.

 

my problem is that the directory name doesn't seem to be getting stored in the variable $dirchoice.

 

this system used to work well.

 

the site has not been used for some time but we want to bring it back online.

solved thanks. 

 

needed $dirchoice = $_GET['dirchoice']; for some reason - never needed it before!!

 

have discarded php_self as suggested and am simply using the page name as follows

<li><a href=<?php echo("photo_gallery3.php?dirchoice=" . $darr[$x]) ?> ><?php echo(str_replace("_"," ",$darr[$x])); ?></a></li> 

Many thanks to both of you who replied.

 

without some help from people such as yourselves it would be much, much more difficult to learn how to use a new language properly.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.