...

View Full Version : variable in URL



rafiki
08-24-2006, 03:41 PM
I need help with getting a variable into the url like




// example url http://example.co.uk
// how do i get it to show http://example.co.uk/index.php?page=news

and how do i redirect the variable news to news.html?



thanks,
newcomer Rafiki

ronverdonk
08-24-2006, 04:09 PM
I would say you just code:

http://example.co.uk/index.php?page=news

But that is probably not what you mean. Please elaborate a little bit more on your problem. Do you generate the URL yourself or ?

Ronald :cool:

rafiki
08-24-2006, 04:16 PM
here is the perfect example i found whilst browsing web
www.tip.it/runescape/index.php?page=prayer_guide.htm

if this gives you a better idea

thanks
Rafiki

Nightfire
08-24-2006, 04:17 PM
<?php
// Example URL: http://example.co.uk/index.php?page=news
// Enter page names here
$page = array('news','blah','de','blahdeblah');

if(isset($_GET['page'])){
if(in_array($_GET['page'],$page)){
//includes html page into the index.php page
include $_GET['page'].'.html';
}else{
include 'index.php';
}
}
?>


Quick simple way

ronverdonk
08-24-2006, 04:18 PM
Still not. DOn't give a sample output, show the code you have.

rafiki
08-24-2006, 04:22 PM
atm i dont have any code at all, i have no php experience just html and javascript, i just have the page which is exampled as news.html and index.html which needs to be converted into php i believe

rafiki
08-24-2006, 04:26 PM
<?php
// Example URL: http://example.co.uk/index.php?page=news
// Enter page names here
$page = array('news','blah','de','blahdeblah');

if(isset($_GET['page'])){
if(in_array($_GET['page'],$page)){
//includes html page into the index.php page
include $_GET['page'].'.html';
}else{
include 'index.php';
}
}
?>


Quick simple way

with this code would i just add the html link like

<a href="http://example.com/index.php?page=news>News</a>?

mlseim
08-24-2006, 04:32 PM
I'm also a bit confused, but maybe this is what they want:


<?php

// example url http://example.co.uk
// how do i get it to show http://example.co.uk/index.php?page=news

$page = $HTTP_GET_VARS['page'];

//and how do i redirect the variable news to news.html?

$location = $page.".html";
header ("location: $location");

?>

Nightfire
08-24-2006, 04:33 PM
Yep. Just make sure the code I put up is where you want the html page adding into your php page. Can also make it redirect to your html page if you want that instead of it being included

Nightfire
08-24-2006, 04:34 PM
I'm also a bit confused, but maybe this is what they want:


<?php

// example url http://example.co.uk
// how do i get it to show http://example.co.uk/index.php?page=news

$page = $HTTP_GET_VARS['page'];

//and how do i redirect the variable news to news.html?

$location = $page.".html";
header ("location: $location");

?>

Using depreciated code there and not even any basic checking :(

rafiki
08-24-2006, 04:35 PM
ill go with nights options thanks so much night, thanks other for input aswell :)

rafiki
08-24-2006, 04:42 PM
night this is my out put code, obviosly the index.php will contain more html,
<html> <head> <title>Example Page</title></head>

<body> <?php

$page = array('news','about','contact','disclaimer');
if(isset($_GET['page'])){
if(in_array($_GET['page'],$page)){
include $_GET['page'].'.html';
}else{
include 'index.php';
}
}
?>

<a href="/index.php?page=news>News</a>
</body></html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum