• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 15:39
CET 21:39
KST 05:39
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
[ASL22] Finals Preview: Sweet Victory!12[ASL22] Ro4 Preview: Mirror Mirror6[ASL22] Ro8 Preview: Within Reach5[ASL22] Ro8 Preview: In A Tizzy11[ASL22] Ro16 Preview: Holy Diver5
Community News
Weekly Cups (Oct 26 - Nov 1): MaxPax, herO, Solar win0Weekly Cups (October 19-25): Clem triples first in 5.0.175Evil Geniuses - shutting down23ISSL (IntoTheTV x SOOP SC2 League): Premier7Weekly Cups (October 12-18): 5.0.17 era begins1
StarCraft 2
General
Serral's getting trashed by New Catsle's Mind No more SC2 streamers on team liquid? StarCraft open world shooter announced at BlizzCon [D] Hacker peak in sc2 ? Liquibets sc2 season 30
Tourneys
SC2 iNu's Battles #22 SC4ALL: II Venue Change Announcement! Sparkling Tuna Cup - Weekly Open Tournament WardiTV Mondays ISSL (IntoTheTV x SOOP SC2 League): Premier
Strategy
[H] ZvP Mid-Late Game: Stalkers Collossi HT
Custom Maps
Starcraft 2 Advance [G] How to playtest arcade maps [D] the control group Simple Questions/Answers
External Content
The PondCast: SC2 News & Results Mutation # 551 Robotic Revival Mutation # 550 Graveyard Shift Mutation # 549 Endless Sparkles
Brood War
General
List of top players active on ShieldBattery Rollback Netcode in Brood War [Megathread] Daily Funny Videos BW General Discussion Cwal.gg not working
Tourneys
[$1250] International ShieldBattery League [Megathread] Daily Proleagues Small VOD Thread 2.0 KCM Race Survival 2026 Season 4
Strategy
50,000-Word Terran Builds Memo 2026-10-22 Cliff Jump Revisited (1 in a 1000 strategy) Simple Questions, Simple Answers
Other Games
General Games
Nintendo Switch Thread General RTS Discussion Thread ZeroSpace Early Access is Now Live! Path of Exile Stormgate/Frost Giant Megathread
Dota 2
Dota 2 Champions League Season 3 Begins April 25!
League of Legends
[TL LoL EUW IHs] Teemo shall perish
Heroes of the Storm
Heroes of the Storm 2.0
Hearthstone
Deck construction bug
TL Mafia
TL Mafia Community Thread
Community
General
US Politics Mega-thread Trading/Investing Thread Russo-Ukrainian War Thread Dating: How's your luck? Things Aren’t Peaceful in Palestine
Fan Clubs
Fan Club Resource Thread Reynor Fan Club The Flash Fan Club
Media & Entertainment
Movie Discussion! Anime Discussion Thread [Manga] One Piece
Sports
Football (Soccer) Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023
World Cup 2022
Tech Support
Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
The time I organised my…
AssyrianKing
Playlenda
Playlendapro
Why I built Repalyzer (1.1.…
BlueStar
Innovate or Game Over?
TrAiDoS
ShieldBattery on Mac
Kraekkling
[ASL22] Ro4 Day1 Ticket Giv…
bITt.mAN
Can Bots Beat Pros?? Starcr…
namkraft
Customize Sidebar...

Website Feedback

Closed Threads



Active: 10164 users

php question

Blogs > Hot77.iEy
Post a Reply
Hot77.iEy
Profile Blog Joined March 2003
Finland1486 Posts
Last Edited: 2009-01-27 07:47:15
January 27 2009 07:41 GMT
#1
I am coding navigation for a website and am using this code for every link in the navbar:

<?php
$default = "home.php";
$allowed = array (
'index',
'example',
);
if( isset( $_POST["P"] ) || isset( $_GET["P"] ))
{
$page = isset($_GET["P"]) ? $_GET["P"] : $_POST["P"];

if( in_array( trim ( $page ), $allowed ))
{
$file = $page . ".php";
if( (file_exists( $file )))
{
include( $file );
}
else
{
include( $default );
}
}
else
{
include( $default );
}
}
else
{
include( $default );
}
?>

Currently it searches for files in the folder where index.php. My question is how can I make it search for files in a sub folder? I have all my sub pages in 'pages' folder. Im guessing i have to change this line:

$file = $page . ".php";

But I dont know how to change the path correctly. I think the period in the middle means "current folder" which I have to change to reflect the path..

I got this from: http://scriptplayground.com/tutorials/php/PHP-Navigation/

-.-
Abydos1
Profile Blog Joined October 2008
United States832 Posts
January 27 2009 08:02 GMT
#2
My knowledge of php is limited so may this be inaccurate.

The . is the string concatenate operator in PHP so $page . ".php" is adding .php on to the end of the page variable which its getting from the post. So + Show Spoiler [code] +
$file = "/pages/" . $page . ".php"
should work for you.

It's also checking the $allowed array to see if its a valid page so make sure all your included pages (just the page name, not folder & .php extension) are included in that array.
"...perhaps the greatest joy possible in Starcraft, being accused of being a maphacker" - Day[9]
Hot77.iEy
Profile Blog Joined March 2003
Finland1486 Posts
Last Edited: 2009-01-27 08:16:21
January 27 2009 08:15 GMT
#3
On January 27 2009 17:02 Abydos1 wrote:
My knowledge of php is limited so may this be inaccurate.

The . is the string concatenate operator in PHP so $page . ".php" is adding .php on to the end of the page variable which its getting from the post. So + Show Spoiler [code] +
$file = "/pages/" . $page . ".php"
should work for you.

It's also checking the $allowed array to see if its a valid page so make sure all your included pages (just the page name, not folder & .php extension) are included in that array.

Thanks alot! That did the trick, though I had to first remove the first forward slash from "/pages/". -> "pages/". It seems I had confused the . when I was reading about include paths in php.ini

Thanks for your help!
-.-
Raithed
Profile Blog Joined May 2007
China7078 Posts
January 27 2009 09:12 GMT
#4
yeah, php is funny that way.
Telemako
Profile Blog Joined September 2002
Spain1637 Posts
Last Edited: 2009-01-27 11:08:30
January 27 2009 11:07 GMT
#5
$file = "/pages/" . $page . ".php"

Here you're linking to ROOT/pages/NAME.php, and without the first / you link to HERE/pages/NAME.php

That's how paths work.

What . means in the code is concatenation of strings. So "bubba" . "babba" = "bubbababba".
I've been around since it all started, and it feels good
Please log in or register to reply.
Live Events Refresh
Monday Night Weeklies
02:00
#69
SteadfastSC400
TKL 395
TaKeTV 391
ZombieGrub144
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
ByuN 478
SteadfastSC 400
TKL 395
mouzHeroMarine 333
ZombieGrub144
EmSc Tv 24
EnDerr 1
StarCraft: Brood War
Shuttle 372
ProTech71
Barracks 25
910 16
Counter-Strike
pashabiceps2236
byalli260
gobbtv231
Heroes of the Storm
Grubby4249
Trikslyr80
Other Games
Liquid`Hasu167
B2W.Neo165
C9.Mang096
NeuroSwarm63
Railgan31
Chillindude20
Organizations
Counter-Strike
PGL67
StarCraft 2
EmSc Tv 24
EmSc2Tv 24
[ Show 12 non-featured ]
StarCraft 2
• Reevou 8
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• Migwel
StarCraft: Brood War
• Eskiya23 29
• BSLYoutube
• STPLYoutube
• ZZZeroYoutube
Other Games
• imaqtpie1170
• Shiphtur658
Upcoming Events
Replay Cast
2h 21m
Sparkling Tuna Cup
13h 21m
WardiTV Invitational
15h 21m
YoungYakov vs Lambo
SHIN vs TBD
Percival vs Shameless
Solar vs TBD
OSC
1d 2h
ByuN vs MaxPax
herO vs Krystianer
Percival vs Shameless
LetaleX vs YoungYakov
Nicoract vs Gerald
GgMaChine vs ArT
PiGosaur Cup
1d 4h
INu's Battles
1d 15h
ByuN vs Classic
3D!Clan Event
1d 19h
The PondCast
2 days
KCM Race Survival
2 days
WardiTV Invitational
2 days
[ Show More ]
Ultimate Battle
3 days
CranKy Ducklings
4 days
IPSL
4 days
TerrOr vs IJ_Terran
rasowy vs Hazorath
Sparkling Tuna Cup
5 days
IPSL
5 days
Art_Of_Turtle vs KameZerg
Radley vs George
Replay Cast
6 days
WardiTV Weekly
6 days
Liquipedia Results

Completed

Proleague 2026-11-06
Blizzard Classic Cup 2026
HCC Season 3

Ongoing

Acropolis #5
KCM Race Survival 2026 Season 4
International ShieldBattery League
Individual League
BSL Season 23
IPSL Winter 2026-27
Calamity Cup Div. A Season 8
IEM Beijing 2026
PGL Masters Bucharest 2026
Stake Ranked Episode 5
1win Private Club #2
Thunderpick World Champ. '26
ESL Pro League Season 24
Stake Ranked Episode 4
1win Private Club #1
Logitech G Play Connect 2026
SL StarSeries Fall 2026
FISSURE Playground #3
BLAST Open Fall 2026

Upcoming

YSL S4
Sector 951
SC4ALL II: Brood War
BSL 23: Non-Korean Championship
HSC XXX
Stellar Fest 2: Lunar Cup
StarCraft2 Weekly Open Tournament 2026 Grand Finals
SC4ALL II: StarCraft II
Kung Fu Cup 2026 Grand Finals
RSL Offline Finals
Underdog Cup 2026 Div 2-3
PGL Bucharest 2027
BLAST Bounty Winter 2027
eXTREMESLAND 2026
PGL Major Singapore 2026
Stake Ranked Episode 6
BLAST Rivals Fall 2026
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2026 TLnet. All Rights Reserved.