PHP=X Code

Soldato
Joined
9 Dec 2006
Posts
9,289
Location
@ManCave
looking for the script that allows, you to set links like ?phpx=home

i'm not sure what to search for, i need it be the secure version, & with Default page.

i tried searching for "php content script" "Php Nav Script"

thanks.
 
Erm, do you have a specific reason for wanting to do this? The best way is just to have a page that includes the header and footer as separate files, e.g.:

PHP:
<?php include 'header.php' ?>
<p>Some content goes here.</p>
<?php include 'footer.php' ?>
 
not using headers or footers :) its just one page that links to multiple sites/ info pages
just looking for the script :(
 
Last edited:
I don't really understand what you're trying to do :confused:

What's wrong with just using "home.php", etc.? What are you expecting the script to do?
 
You want to add on a query string to the end of the link, you could maybe just use a find/replace in some editor like word.

find/replace-all = html
replace all with html?a=default
 
Any good? Call with page.php?x=file_to_include (without extension)

PHP:
<?php
echo includeContent($_GET['x']);

function includeContent($x) {
	// Default page if $x doesn't exist or
	// isn't specified
	$default = 'index';
	
	// File extension of the file to include
	// i.e. given $x=info we want to include
	// info.php
	$extension = '.php';
	
	// Only allow alphanumeric characters
	$x = preg_replace('/[^a-z0-9]/i', '', $x);
	
	// If $x isn't set then or $x doesn't exist
	// use the default page
	if ( !isset($x) || !file_exists($x.$extension) )
		$x = $default;
		
	// Just incase $default doesn't exist
	if (file_exists($x.$extension))
		include($x.$extension);
}
?>
 
Last edited:
I don't see why you'd want to use that approach in the first place though. It just introduces unnecessary code and makes the URL look messy.
 
unless i'm reading it completely wrong isn't this one of the better ways to do it? like wordpress does.

Wordpress is a more complicated case because it's not simply including files; it's having to parse URL information and generate content based on that information, so it make sense to have it originating from a single file.

In this case, however, the only thing it's doing is including a file, so it's completely redundant to put some intermediate code in there to include the file for you when you could just cut out the middle man. This is exactly what the server's URL parsing routines are for.

Think about it: what benefit is there in using "index.php?page=home" rather than simply "home.php"? A possible justification would be so you could execute some common code on every page, but even then it's generally better just to include a header/footer on each page (except in the case of a much more sophisticated application like Wordpress).
 
Last edited:
Any good? Call with page.php?x=file_to_include (without extension)

PHP:
<?php
echo includeContent($_GET['x']);

function includeContent($x) {
    // Default page if $x doesn't exist or
    // isn't specified
    $default = 'index';
    
    // File extension of the file to include
    // i.e. given $x=info we want to include
    // info.php
    $extension = '.php';
    
    // Only allow alphanumeric characters
    $x = preg_replace('/[^a-z0-9]/i', '', $x);
    
    // If $x isn't set then or $x doesn't exist
    // use the default page
    if ( !isset($x) || !file_exists($x.$extension) )
        $x = $default;
        
    // Just incase $default doesn't exist
    if (file_exists($x.$extension))
        include($x.$extension);
}
?>

Thanks a lot!. will use that soon.

Inq, i find this the easiest way, i been out of the coding area for a very long time & just wanted to get my site done the easiest way possible,

the site in question that will be using the code is www.smogsy.co.uk the content code will be used for the 3 coming soon links.
 
Inq, i find this the easiest way, i been out of the coding area for a very long time & just wanted to get my site done the easiest way possible,

Ok, but I don't understand what's easier about it; you don't have to do this at all!

The "index.php?page=abc" URI scheme is unnecessary in most cases. The only cases in which it makes sense are those in which you're not actually serving files but are generating content through some other mechanism (e.g. Wordpress, MVC frameworks, etc.)
 
Last edited:
Ok, but I don't understand what's easier about it; you don't have to do this at all!

The "index.php?page=abc" URI scheme is unnecessary in most cases. The only cases in which it makes sense are those in which you're not actually serving files but are generating content through some other mechanism (e.g. Wordpress, MVC frameworks, etc.)

one reason i find it easier is that referencing a file will always be the same as you never actually move.

another is i find it makes the files much tidyier. e.g. i can have ?p=about which goes into the about folder and includes sub nav links for about, then if &s=me is set then i can go into sub nav folder and collect the files needed for me. it also then means i can include me content on another page but only have one file for the text.
 
Back
Top Bottom