PDA

View Full Version : Getting Data?


jasondf
08-27-2002, 02:41 AM
Hey,
I have seen sites that have an address like "view.php?num=3157" and it loads a certain page. Changing the number loads a different page. I was wondering how to do this, because I'm making a source code bank. I would like to be able to load source code by doing something like "view.php?num=2424" or whatever. I would appreciate any help directing or telling me how to do this.

Thanks

firepages
08-27-2002, 05:11 AM
well all depends on where/ how you are storing your data...

when you call 'view.php?num=3157'
the variable $num can be accessed via both $HTTP_GET_VARS['num'];//(all versions) or
$_POST['num'];//(PHP4.1.0+);

so you now have your variable $_POST['num'] containing '3157'

if you were storing your data in a database you might now do something along the lines of...

mysql_query("SELECT * FROM $table WHERE id=$_POST['num']");
and process the returned result set

OR you may have your script in a suitably named file...

<?
if($_POST['num']){
readfile('/home/user/www/pages/'.$_POST['num'].'.txt');
}
?>


which would echo the file to screen (you could use file() fopen etc to manipulate the file first should you wish)

NOTE its really important to use the path to your file '/home/user.. etc to stop peeps from trying to look elsewhere in your filesystem.