include suitable php files by using $_SERVER['PHP_SELF'] or

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
disconne
Forum Newbie
Posts: 9
Joined: Fri Sep 19, 2008 3:31 am

include suitable php files by using $_SERVER['PHP_SELF'] or

Post by disconne »

Hi all,

how can i achieve to include suitable inc or php files by only using the address bar info..
I mean for example one way may be

if $_SERVER['PHP_SELF'] = X include A, B, C, D
if $_SERVER['PHP_SELF'] = Y include A, G, E, D

i had some code with this structure but it does not work... Maybe you may advise more easy and safe methods for this

best regards
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: include suitable php files by using $_SERVER['PHP_SELF'] or

Post by jaoudestudios »

Do you mean...

Code: Select all

 
if ($_SERVER['PHP_SELF'] == 'page1.php') {
   include('another_page.php');
}
 
Why do you want to do this? Is it for a template system? Because there are better ways to do it!
disconne
Forum Newbie
Posts: 9
Joined: Fri Sep 19, 2008 3:31 am

Re: include suitable php files by using $_SERVER['PHP_SELF'] or

Post by disconne »

hi jaoudestudios,
thanks for quick reply.

yes I want to do that let's say for my template system. Actually I've done it with the way you wrote but somehow my code always brings my index.php
the code is below

1 - please help me where am I wrong? ( there is no parse or fatal error on my live page ) and I ve checked the if elseif else while etc brackets
2 - please mention about the better ways, i love php so i can study to learn

my live code is below:
note: $altdizin value is /0/
and whether my firefox address is http://.../0/index.php or http://.../0/php/tamyazi.php , page is always same (http://.../0/index.php)

for hours, i couldn't understand why i always see my index page although the page address is http://.../0/php/tamyazi.php.
in my code number line 85: i say : elseif ($_SERVER['PHP_SELF'] == $altdizin."php/tamyazi.php")


every help will be appreciated buddy

Code: Select all

 
<?php
if ($_SERVER['PHP_SELF'] == $altdizin."index.php") //anasayfa kontrolu
{//anasayfa kontrolu if baslangici
 
echo "\n\n<div id=\"spot1\">\n\n";
$q1  = "SELECT id FROM dis_yazilar";
$r1 = mysql_query($q1);
$nrr1 = mysql_num_rows($r1);
$nummod1 = fmod($nrr1,2);
 
 
$quespot1  = "SELECT id, baslik, yazar, image_alt, icerik FROM dis_yazilar WHERE mod(id,2)=$nummod1 ORDER BY id DESC limit 4";
$respot1 = mysql_query($quespot1);      
include("{$kokdizin}functions/func_shorten_string.php");
include("{$kokdizin}functions/func_spot_ozet_temizle.php");
while($ro1 = mysql_fetch_row($respot1))
{
    $id1    = $ro1[0];
    $baslik1 = $ro1[1];
    $yazar1 = $ro1[2];
    $image_alt1 = $ro1[3];
    $icerik1 = $ro1[4];
 
echo "<img width=\"90px\" height=\"90px\" alt=\"".$image_alt1."\" title=\"".$image_alt1."\" src=\"".$altdizin."resim/$id1.jpg\" />\n";
echo "<span class=\"spotbaslik\">".$baslik1."</span> - <span class=\"spotyazar\">".$yazar1."</span><br />\n";
 
$hamveri = shorten_string($icerik1, 36);
 
spot_ozet_temizle($hamveri);
 
echo "<a href=\"".$altdizin."php/tamyazi.php?id=".$id1."\">Yazýnýn devamý için týklayýnýz</a><hr />\n\n";
}
echo "</div>\n\n";
echo "<div id=\"spot2\">\n\n";
 
$q2  = "SELECT id FROM dis_yazilar";
$r2 = mysql_query($q2);
$nrr2 = mysql_num_rows($r2);
$nummod2 = fmod($nrr2,2);
 
if ( $nummod2 == 1 )
{
$quespot2 = "select id, baslik, yazar, image_alt, icerik from dis_yazilar where mod(id,2) = 0 order by id desc limit 4";
$respot2 = mysql_query($quespot2);
while($ro2 = mysql_fetch_row($respot2))
{
    $id2    = $ro2[0];
    $baslik2 = $ro2[1];
    $yazar2 = $ro2[2];
    $image_alt2 = $ro2[3];
    $icerik2 = $ro2[4];
 
echo "<img width=\"90px\" height=\"90px\" alt=\"".$image_alt2."\" title=\"".$image_alt2."\" src=\"".$altdizin."resim/$id2.jpg\" />\n";
echo "<span class=\"spotbaslik\">".$baslik2."</span> - <span class=\"spotyazar\">".$yazar2."</span><br />\n";
$hamveri = shorten_string($icerik2, 36);
spot_ozet_temizle($hamveri);
echo "<a href=\"".$altdizin."php/tamyazi.php?id=".$id2."\">Yazýnýn devamý için týklayýnýz</a><hr />\n\n";
}
echo "</div>\n\n";
}
else
{
$quespot3  = "SELECT id, baslik, yazar, image_alt, icerik FROM dis_yazilar WHERE MOD(id,2) = $nummod2+1 ORDER BY id DESC limit 4";
$respot3 = mysql_query($quespot3);
 
while($ro3 = mysql_fetch_row($respot3))
{
    $id3    = $ro3[0];
    $baslik3 = $ro3[1];
    $yazar3 = $ro3[2];
    $image_alt3 = $ro3[3];
    $icerik3 = $ro3[4];
 
echo "<img width=\"90px\" height=\"90px\" alt=\"".$image_alt3."\" title=\"".$image_alt3."\" src=\"".$altdizin."resim/$id3.jpg\" />\n";
echo "<span class=\"spotbaslik\">".$baslik3."</span> - <span class=\"spotyazar\">".$yazar3."</span><br />\n";
$hamveri = shorten_string($icerik3, 36);
spot_ozet_temizle($hamveri);
echo "<a href=\"".$altdizin."php/tamyazi.php?id=".$id3."\">Yazýnýn devamý için týklayýnýz</a><hr />\n\n";
}
echo "</div>\n\n";
}
 
}//anasayfa kontrolu if bitimi
elseif ($_SERVER['PHP_SELF'] == $altdizin."php/tamyazi.php") //yazilar sayfasi kontrolu
{//yazilar sayfasi kontrolu elseif baslangici
 
echo "tamyaziadres";
 
} //yazilar sayfasi kontrolu elseif bitimi
 
else {echo "hata! 2";}
?>
 
Post Reply