Jump to content


Photo

how to code index.php?page=1


  • Please log in to reply
5 replies to this topic

#1 chrisjunkie

chrisjunkie
  • New Members
  • Pip
  • Newbie
  • 7 posts

Posted 16 October 2006 - 04:58 AM

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

#2 trillion

trillion
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 16 October 2006 - 07:08 AM

if you enter in the url

test.php?category=test

this code in test.php file:
<?php
if ($category == "test") {
    echo "<div id='test'>
  TEST!
</div>";
}
?>

will return:
TEST!

but register globals has to be on

#3 akitchin

akitchin
  • Staff Alumni
  • Advanced Member
  • 2,516 posts
  • LocationCalgary, AB, Canada

Posted 16 October 2006 - 07:09 AM

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.

#4 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 16 October 2006 - 08:11 AM

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

<?php

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

?>

or

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

?>

Just remember to untained $_GET["page"] to prevent SQL injections or file redirects.
SA PHP Archives - www.phparchives.za.org

#5 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 16 October 2006 - 10:32 AM

Always valadate a $_GET ok.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#6 xsist10

xsist10
  • Members
  • PipPipPip
  • Advanced Member
  • 114 posts

Posted 16 October 2006 - 10:37 AM

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

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

SA PHP Archives - www.phparchives.za.org




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users