Jump to content

Archived

This topic is now archived and is closed to further replies.

tomjones

generating pages with custom strings as urls

Recommended Posts

Hi,

I would like to know how to generate pages such as www.domain.com/file.php?12345 or www.domain.com/file.php?678910.

Any advice or links appreciated. Thank you.

Share this post


Link to post
Share on other sites
look at $_GET[' '] ok.


test.php
<?
echo"<a href='test_result.php?php=freaks'>go to page</a>";
?>


test_result.php
<?
if(!$_GET['php']=='freaks') {

do somthink

}
?>

Share this post


Link to post
Share on other sites
I did not see the correlation when experimenting with the above example. More specific I am trying to generate pages with custom names from an array, like www.domain.com/page.php?foo1 and www.domain.com/page.php?foo2. I Just need to know how to create these urls with php.. thanks.

Share this post


Link to post
Share on other sites
may be a switch statement is what you are wanting.

[code=php:0]<?php
function getpage($showpage) {
    switch ($showpage) {
        case "your_page":
//put the php here
        break;
        case "your_next_page":
//put another page here
        break;
    default:
//your default page
    }
}
getpage($_GET['showpage']);//you need this to execute your code
?>[/code]

A link for this would be whatever.php?showpage=your_page


Hope that helps

Tom

Share this post


Link to post
Share on other sites
^ It's exactly what redarrow said.

You use the $_GET superglobal to track what link to go to. Example:

if (isset($_GET['link'])) {
   $link = $_GET['link'];
   if ($link == 3) {
       // Include links for page.php?link=3
   }
   elseif ($link == 5) {
       // page.php?link=5
   }
   else {
       die ('You are not using a valid link');
   }
}
else {
   // Show page.php
}

You can repeat the elseif statement for however many you want different stuff to show up. There are many ways of using the $_GET superglobal to create those kinds of links.

Share this post


Link to post
Share on other sites

×

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.