• Unfortunately, we have experienced significant hard drive damage that requires urgent maintenance and rebuilding. The forum will be a state of read only until we install our new drives and rebuild all the configurations needed. Please follow our Facebook page for updates, we will be back up shortly! (The forum could go offline at any given time due to the nature of the failed drives whilst awaiting the upgrades.) When you see an Incapsula error, you know we are in the process of migration.

PHP link in the adress bar

Junior Spellweaver
Joined
Oct 18, 2005
Messages
181
Reaction score
0
Hello, I want to know how to make in the adress bar link on php

Example:
I have index.php and about.php
How to make
adres/index.php?about

and it will show about.php?

I have tried
<php
if(!empty($_GET['about'])){ include('about.php'); die();}
>

But it doesn't work as good as i want, it shows
adres/about
for about.php , but i need index.php?about or index.php?op=about

Please, if you know how to do it, help me. :lamo:
 
Last edited:
Divine Celestial
Loyal Member
Joined
Nov 11, 2004
Messages
810
Reaction score
0
try this
PHP:
if(isset($_GET['op'])) {
   if(file_exists($_GET['op'] . '.php')) {
      include($_GET['op'] . '.php');
   } else {
      if(!empty($_GET['op'])) {
         echo "Please enter a valid page.";
      } else {
         echo "Please enter a page to go to.";
      }
   }
}

or if you want to make your code run faster, use cases.

[N]asser` ~ Out
 
Skilled Illusionist
Loyal Member
Joined
Aug 31, 2004
Messages
365
Reaction score
1
Where would We put this script ?
 
Divine Celestial
Loyal Member
Joined
Nov 11, 2004
Messages
810
Reaction score
0
On index.php?

[N]asser` ~ Out
 
Junior Spellweaver
Joined
Oct 18, 2005
Messages
181
Reaction score
0
yes, It suppose to go to the index.php

[N]asser, thanx for code, but there is error, I do not know where, but if I'm pressing link, it goes into index.php, always.
 
Last edited:
Custom Title Activated
Loyal Member
Joined
Dec 31, 2004
Messages
4,091
Reaction score
25
Code:
<?php

$page = $_GET['page'];
$extension = '.php';

$page = $page . $extension;

if(!file_exists($page)) {

include 'index.php';

}
else {

include $page . '.php';

}

?>

Try that.
 
Divine Celestial
Loyal Member
Joined
Jul 8, 2005
Messages
888
Reaction score
20
Mr.X said:
Code:
<?php

$page = $_GET['page'];
$extension = '.php';

$page = $page . $extension;

if(!file_exists($page)) {

include 'index.php';

}
else {

[b]include $page . '.php';[/b]

}

?>

Try that.
look at the bolds. doesn't $page already include $extension (.php)?
 
Divine Celestial
Loyal Member
Joined
Nov 11, 2004
Messages
810
Reaction score
0
Besides, if errors are on and they havn't set $_GET['page'], it'll display an error.

PS - Gashek, try to go to index.php?op=about. It won't redirect you to about.php, but just includes it. If you want to redirect to that page, use the following code:
PHP:
if(isset($_GET['op'])) {
   if(file_exists($_GET['op'] . '.php')) {
      header("Location: " . $_GET['op'] . '.php');
   } else {
      if(!empty($_GET['op'])) {
         echo "Please enter a valid page.";
      } else {
         echo "Please enter a page to go to.";
      }
   }
}

[N]asser` ~ Out
 
Custom Title Activated
Loyal Member
Joined
Aug 8, 2004
Messages
3,892
Reaction score
20
That code is insecure. Don't use it.

Here's a bit of sourcecode from Volamir:
PHP:
$params = array_slice(explode("/",checkVar(strtolower($_SERVER["REDIRECT_URL"]))),1);
$userdata = getUserData();

switch ($params['0']) {
  case 'accnt':
    if($userdata or $params['1'] == ('new' || 'save')) {
    	include("account.inc.php");
			accountHandler($params['1']);
			break;
		}
	case 'chars':
		if($userdata) {
			include("charSelect.inc.php");
			charHandler($params['1'], $params['2']);
			break;
		}
	 case 'battle':
	 	if($userdata) {
	    include("battlefield.inc.php");
  	 	battlefield($params['1']);
	 		break;
	 	}
  case 'index':
	 	default:
		welcome();
	 	break;
}

Subsequentally, the different cases load their own template:
PHP:
function newAccount() {
	/* LOAD NEW-ACCOUNT TEMPLATE */
	$smarty = new smarty_connect;
  	$smarty->caching = true;
  	$smarty->display('newAccount.tpl');
}

Works fast as hell due to Smarty (which can cache template files and output) and is incredibly easy to maintain due to each page has its own case.

Now, if I for example go to fragfrog.nl/accnt/new/ it'll automatically display the new account form.

I suggest you start reading :)

(by the way, this won't work directly if you copy paste it since you don't have my include file (which for example has the checkVar function that prevents any injection whatsoever). Source protection and all that. But it should give you a pretty good idea what I'm talking about.)
 
Last edited:
Junior Spellweaver
Joined
Oct 18, 2005
Messages
181
Reaction score
0
thanx all for answer, I've tried 3 codes, and I was satisfied about the result.

To FragFrog: thanx for link, but I found another one, it's
It's much easier to find and learn.

Thanx all for answering.
 
Back
Top