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

Link to comment
Share on other sites

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';

Link to comment
Share on other sites

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');}

?>

Link to comment
Share on other sites

<?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');
}
?>

Link to comment
Share on other sites

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);
}

Link to comment
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.