Jump to content

Php Url parameter


adamriley

Recommended Posts

Just for the last question if i wanted to change the parameter "$c" to a number and have the script see the number and change it to a folder for example the url would be "sitemap.php?a=1&b=php&c=1"

the c  parameter would relate to a folder for example "pages" then the script would show the file "pages/1.php" if to confussing just say and i will try and word it in a way you understand

I think I understand let me throw this at ya..

<?php
$directories = array(1=>'pages');
if (isset($_GET['a']) && isset($_GET['b']) && isset($_GET['c']) && $_GET['c'] !='' && $_GET['a'] != '' && $_GET['b'] != '') {
   $a = $_GET['a'];
   $b = $_GET['b'];
   $c = $_GET['c'];
   if (!isset($directories[$c]) && !@include($directories[$c].'/'.$a.'.'.$b)) {
     echo 'Page you are requesting doesnt exist';
   }
} else {
   include ('pages/1.php');
}
?>

 

Then all you have to do is create different associations in the directories array like $c being 4 might point to images.

so you would add

$directories = array(1=>'pages',4=>'images');
// or
$directories = array();
$directories[1] = 'pages';
$directories[4] = 'images';

it does not work a blank screen url is "?a=1&b=php&c=1" is it right

 

<?php

$directories = array(1=>'pages');

if (isset($_GET['a']) && isset($_GET['b']) && isset($_GET['c']) && $_GET['c'] !='' && $_GET['a'] != '' && $_GET['b'] != '') {

  $a = $_GET['a'];

  $b = $_GET['b'];

  $c = $_GET['c'];

  if (!isset($directories[$c]) && !@include($directories[$c].'/'.$a.'.'.$b)) {

    echo 'Page you are requesting doesnt exist';

  }

} else {

  include ('pages/1.php');}

?>

<?php
$directories = array(1=>'pages');
if (isset($_GET['a']) && isset($_GET['b']) && isset($_GET['c']) && $_GET['c'] !='' && $_GET['a'] != '' && $_GET['b'] != '') {
$a = $_GET['a'];
$b = $_GET['b'];
$c = $_GET['c'];
if (isset($directories[$c])) {
	if (!@include($directories[$c].'/'.$a.'.'.$b)) {
		echo 'Page you are requesting doesnt exist';
	}
} else {
	echo 'Page you are requesting doesnt exist';
}
} else {
include ('pages/1.php');
}
?>

Something like this should work

// Setup our paths, 0 is always default
$directories = array(0=>'pages',1=>'images');
// Get First parameter, if non-existant or empty, set default to '1'
$a=isset($_GET['a'])?(!empty($_GET['a']?$_GET['a']:'1'):'1';
// Get Second parameter, if non-existant or empty, set default to 'php'
$b=isset($_GET['b'])?(!empty($_GET['b']?$_GET['b']:'php'):'php';
// Get Third Paramter, if non-existant or empty, set default to 0
// if not in array of pages set default
$c=isset($_GET['c'])?(!empty($_GET['c']?(isset($directories[$_GET['c']]?$_GET['c']:0):0):0;
// Check if the page exists, if not show error
if(!file_exists($page="{$directories[$c]}/{$a}.{$b}"))
{
  echo 'Page you are requesting doesnt exist';
} else {
// Otherwise grab the page
  @include($page);
}

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.