Jump to content

how to code index.php?page=1


chrisjunkie

Recommended Posts

Hi there people,

As i am a n00b  ;D  I need to ask questions hehehe

What i want to do is have it so i can type index.php?page=1 and have page 1 show up. I know this can be done and I have looked at php code that does this but i cant quite nut it out. Any help greatly appreciated
Link to comment
Share on other sites

do NOT expect to be able to use $category locally upon entering a URL like that.  register_globals has been turned off by default since PHP something.or.other.that's.fairly.old.

use superglobals like $_GET['category'].  read more about it in the manual, and/or here in the FAQ/code snippets forum because this is a very common question.
Link to comment
Share on other sites

It depends on where you are going to be storing page 1.
Will it be pulled from a database or from a file?

[code]
<?php

if ($_GET["page"]) {
    require_once("/pages/". $_GET["page"] .".php");
}

?>
[/code]

or

[code]
<?php

if ($_GET["page"]) {
    // get page from database
    $sql = 'SELECT contents FROM pages WHERE id='. $_GET["page"];
    // use your database engine / class / generic to get the result
    // $db->getOne($sql);    <--- Pear DB Manager
    echo $result;
}

?>
[/code]

Just remember to untained $_GET["page"] to prevent SQL injections or file redirects.
Link to comment
Share on other sites

I remember at least passing all your user-received values through something like this:

[code]
<?php
function removeBadWords($src) {
$filter = array("INSERT INTO ", "SELECT ", "UPDATE ", "JOIN ", "UNION ", "MODIFY TABLE ", ";", "DELETE ");
$replacements = array_fill(0, count($filter), "");
return addslashes(strip_tags(str_ireplace($filter, $replacements, $src)));
}
?>
[/code]
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.