Register


Active : 793
Logged in : 231
Time: 22:27 KST

User Streams
39 online (3 live)
Home | Forum | VODs | Liquibet | Fantasy | Blogs | Liquipedia | Articles | Store
Search TeamLiquid.net
Starcraft Progaming News
[TSL] Go Go Go!
[PL] Lim-Jin Rok
[TSL] Ladder with Legends
[OSL] The End of the Begi…
[MST] The Beginning of th…
Featured Threads
TL User Locations
Recommended VODs of rece…
Small Vod Thread.
Funny Quotes from TL's I…
Team Liquid Manpower
General Forum
Marijuana in American Cu…
"Fall of the Republic"
Arrested for not paying …
How to enjoy life?
PokerStrategy.com Q&A Th…
Starcraft 2 Forum
Vote for SC2 in Spike's …
StarCraft II Q&A Batch 55
Zerg spies?
Data Editor: Mod Examples
Excited about Planetary …
Starcraft: Brood War Forum
[Photos] Post EVER Group…
[Interview] SPL Wemade v…
[Interview] SPL KT vs Ace
[CSL+] News and Announce…
Help with weird iccup er…
Starcraft Tournaments and Leagues
[SPL] SK Telecom T1 vs W…
[SPL] STX Soul vs Samsun…
[SPL] Airforce ACE vs KT…
iG showmatch
[OSL] Group Selection
Starcraft Strategy Forum
[Q] Gas Timings for 3Hat…
Why does destination fav…
ZvT 3 Hatch Muta - Adapt…
[Guide] Map Analysis - F…
[Q]Protoss FE vs 5 pool?
Sports & Games Forum
League of Legends
UFC 105 (Nov 14) + UFC 1…
[HoN/DotA] Let's Play~!!
Battlefield Bad Company 2
TL Chess Match
Blogs
Starcraft Replays
KawaiiRice - MistrZZZ
By.FlaSh - Best[WHITE]
By.FlaSh - Tempest)Is(
Light[aLive] - By.hero
Bisu - HyuK


Website Feedback

Closed Threads

IRC Updated
irc.quakenet.org #teamliquid

IRC Web Client
New to Team Liquid? Register here!

php question

Join the PokerStrategy.com TSL ladder for a chance at $22,000 in prizes!
Forum index > Blogs
  Hot77.iEy   Finland. January 27 2009 16:41. Posts 1463Profile Blog 
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/
Last edit: 2009-01-27 16:47:15


-.-
Old Post

  Abydos1   United States. January 27 2009 17:02. Posts 825Profile Blog 
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] +
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]
Old Post

  Hot77.iEy   Finland. January 27 2009 17:15. Posts 1463Profile Blog 

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] +
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!
Last edit: 2009-01-27 17:16:21
-.-
Old Post

  Raithed   China. January 27 2009 18:12. Posts 6746Profile Blog 
yeah, php is funny that way.
http://raith.freehostia.com
Old Post

  Telemako   Spain. January 27 2009 20:07. Posts 1441Profile Blog 
$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".
Last edit: 2009-01-27 20:08:30
I'll pay you for SC2, then for the expansion, then for the next expansion, and then for battlenet and then I'll realize you waited too much to give me the game, that I grew too old, and I'll return the hate 1000x times
Old Post

 
Calendar
Mo Tu We Th Fr Sa Su
      1
2345678
9101112131415
16171819202122
23242526272829
30      

ON AIR:
→ [TSL] Ladder Start

Live user streams:
ret
[ Show 2 non-featured ]

Upcoming events:  [ More ]
Nov 22  [PL] STX vs KHAN
Nov 22  [PL] hite vs MBC
Nov 23  [KDL] Week 1 Day 1
Team Liquid Progaming Database

League Standings:
» Shinhan 09-10 Proleague
» EVER 2009 OSL
PokerStrategy.com TSL Forum
TSL Ladder Standings
TSL Cheerfuls
Official Raffle Entries
TSL Player Eligibility a…
TSL map pool?
Final Edits: Progaming Editorials
On The Shoulders of Giant…
Here To Stay
A Finale in Five
Masters of the Universe
Map of the Swarm
Power Rank: Progamer Rankings
1. Flash 6. Fantasy
2. Jaedong 7. Effort
3. Inter.Calm 8. Shine[Kal]
4. Stork[gm] 9. HyuK
5. Bisu 10. Kal
   Comments (304)
Poll
TSL Ladder #1?

Comments (132)      Older Polls


International Cyber Cup

Liquid Poker
Sitemap Contact Poker Forum

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2002-2009 Teamliquid.net. All Rights Reserved