andrewgk Posted December 5, 2008 Share Posted December 5, 2008 Hi, I'm new to php and since it makes life so easy I decided to include it in my page and was wandering if you could help me. First of all I wanted to make a simple menu which would apply id to the link of currently being viewed site. And after hours of googling I made something like this: <ul> <li><a<?php if (basename($_SERVER['SCRIPT_NAME']) == "index.php") if ($id=="") echo " id='current'"; else if ($id=="home") echo " id='current'";?> href="?id=home">Home</a></li> <li><a<?php if ($id=="portfolio") echo " id='current'";?> href="?id=portfolio">Portfolio</a></li> <li><a<?php if ($id=="about") echo " id='current'";?> href="?id=about">About Me</a></li> <li><a<?php if ($id=="contact") echo " id='current'";?> href="?id=lol/contact">Contact</a></li> </ul> and since I want to make my site more "edit" friendly I include my content files in my index.php <?php if($id) include("$id.php"); else include("home.php"); ?> So far it works great. As you can see if I would like to point to a file for ex. "site/images/dazy.php" all I have to do is make a link to "index.php?id=site/images/dazy". Here is where I have a problem... Lets say I don't want my visitors to see all that long link or the location of the file on my server. Is there a way I could define an alias to a link for ex. "index.php?id=dazy" would point to "site/images/dazy.php" and so I would just have to include a file with the list of my aliases in the index.php and then just recall them if I need to ( I'm guessing it wont work without <? ?> tag?). Also is there a way of making my current code any smaller/better? Sorry for my english, it is not my first language. Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/135708-include-alias/ Share on other sites More sharing options...
andrewgk Posted December 6, 2008 Author Share Posted December 6, 2008 Got my answer on other forum... <?php $aliases = array("home" => "home.php", "portfolio" => "portfolio.php", "about" => "about.php", "contact" => "lol/contact.php"); ?> and <?php $id = $_GET['id']; if ($aliases[$id]) include($aliases[$id]); else if ($id == FALSE) include ("home.php"); else include ("404.php"); ?> Thanks anyway... Quote Link to comment https://forums.phpfreaks.com/topic/135708-include-alias/#findComment-707555 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.