Jump to content

Constant Variable


vicodin

Recommended Posts

I am working on creating like a framework for my site and i want to create a constant variable like $pagename = "Index" and now when i include my functions and i call for the variable $pagename will it look at the constant variable $pagename? If it will not how do i get it to use the constant?

Link to comment
https://forums.phpfreaks.com/topic/114849-constant-variable/
Share on other sites

hmm,

 

I use a similar thing for my pages.. where I have an index page then all my other site pages are included to that page... and I just use the "$_GET" to change includes..

 

index.php:

<?php

if(isset($_GET['p']))
{
if($_GET['p']=='home')
{
include('home.php');
}
}

?>

 

then the navigation links on my site look like this

 

http://mysite.com/?p=index

 

 

i think it works rather well myself

Link to comment
https://forums.phpfreaks.com/topic/114849-constant-variable/#findComment-590587
Share on other sites

You can also just get the name of the current page with this:

 

<?php

$this_page = basename($_SERVER['REQUEST_URI']);

if (strpos($this_page, "?") !== false) $this_page = reset(explode("?", $this_page));

?>

 

Just clean up the string a bit more and you'll always know where you are.

Link to comment
https://forums.phpfreaks.com/topic/114849-constant-variable/#findComment-590604
Share on other sites

This does work.

 

 

Function...

function linkto_unlesspage($name,$link,$extra = NULL){
$pagename = constant("page");
if (!($name == $pagename)){
echo '<a href="'.$link.'" '.$extra.'>'.$name.'</a>';
}else{
	echo $name;

 

 

page...

define("page","Home");
include('func.inc');
linkto_unlesspage("Home","index.php");

Link to comment
https://forums.phpfreaks.com/topic/114849-constant-variable/#findComment-590653
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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