Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/135708-include-alias/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/135708-include-alias/#findComment-707555
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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