Jump to content

Dir name != Page name = Redirect???


jacko310592

Recommended Posts

hey guys

 

can anyone think of how will i be able to change the following to make it so the glob function will find the names of all the dir's within current dir, then if the page name (declared via $thisPage) doesnt match one of the dir’s found then it will redirect

 

the reason i want to do this is because my album pages are set via URLs like the following:

 

www.mysite.com/gallery/album.php?first_album

www.mysite.com/gallery/album.php?second_album

www.mysite.com/gallery/album.php?third_album

 

 

i have the following code which grabs anything after the "?" which then uses what it finds as the '$thisPage'

<?php
$strArr = explode("?", $_SERVER["REQUEST_URI"]);
$thisDirectory = $strArr[sizeof($strArr) - 1];
$thisPage = $thisDirectory;
?> 

 

 

then i have this so far for the glob part:

$galleryDir = glob('*', GLOB_ONLYDIR);
   foreach($galleryDir as $i=>$file) {
          $dirLocation = $galleryDir[$i];}

 

 

 

basically i want the code to say:

if $thisPage is not equal to $dirLocation then redirect

 

i hope ive explained it well enough, thanks guys

Link to comment
https://forums.phpfreaks.com/topic/183147-dir-name-page-name-redirect/
Share on other sites

all ive managed to make so far is this:

 

<?php $galleryDir = glob('*', GLOB_ONLYDIR);
   $galleryDir = array($galleryDir);
	  
$strArr = explode("?", $_SERVER["REQUEST_URI"]);
$thisDirectory = $strArr[sizeof($strArr) - 1];
$thisPage = $thisDirectory; 

if ($thisPage != $galleryDir) {
header('Location: ./index.php');
     	exit (0);
}
?>

 

but this redirects no matter what, more than likey beacuse its reading the array all as one word, or its looking for each word from the array within the $thisPage.

can anyone think of a way to make it so it scans each file found (placed into the array) and see's if one of them match with $galleryDir

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.