Page 1 of 2

forum.php?linkhere

Posted: Wed Dec 03, 2003 4:12 pm
by dull1554
i'm writing a forum and i wanted to make it so the catagories would link to another section of forum.php, i was wondering how to make a link like forum.php?php I know that the "php" has to be defined somewhere else, but thats what i dont know how to do that, i looked in the manual and i just can't figure it out, any help would be greatly appreciated!

Posted: Wed Dec 03, 2003 4:26 pm
by dull1554
any help would be awesome

Posted: Wed Dec 03, 2003 4:57 pm
by d3ad1ysp0rk
could you be a lil more descriptive of your problem?

not really getting what u want.. :|

Posted: Wed Dec 03, 2003 5:00 pm
by dull1554
maybe i'm not being clear enough,
I want to do this
forum.php

Code: Select all

//code here
Print <<<END
<a href='forum.php?thread1' target='main'>thread 1</a>
END;

//define thread1

$thread1 = "blah";//i don't know if this is how i would do this, could somone please help

//php

Posted: Wed Dec 03, 2003 5:08 pm
by d3ad1ysp0rk
still not understanding, so ill just help u with a few other things while u try to explain it to my stupid mind.. :p

if you're only echoing one line, theres no need to use here.doc.
also, END is a bad value for here.doc, as it is used in text a good amount (ie. the end, etc)

use something that you would never type for the value, ie:

Code: Select all

echo <<EOT
<a href="forum.php?t=$thread" target="main">Thread 1</a>
EOT;
EOT means "End Of Text" and is used a lot (i also believe its the example at php.net)

is this going to be where all the topics are listed? like where all the topic names go, and u click it to bring you to the topic? im still not quite understanding.. sorry..

Also another thing to remember about here.doc that i forget a lot, it needs to have NO spaces infront of it (can't be tabbed in, etc..)

so

Code: Select all

echo <<<M43M
my HTML stuFFF!
  M43M;
wont work, but..

Code: Select all

echo <<<M43M
my HTML stuFFF!
M43M;
will :D

Posted: Wed Dec 03, 2003 5:19 pm
by dull1554
what i want to do is to have a few sections in forum.php, in each section i will have a bunch of html defined, and then i want to call those sections with form.php?whatever_section_i_want
i hope this is a bit more understandable

Posted: Wed Dec 03, 2003 5:21 pm
by DuFF
I'm not quite sure what you mean either but maybe you're looking for query strings? Something like this?

Code: Select all

http://www.example.com/forum.php?forumid=3&amp;topicid=8
If that is what you are looking for then on the forum.php you could do this:

Code: Select all

<?php
echo "Forum ID:" . $_GET['forumid']; //will echo 3
echo "Topic ID:" . $_GET['topicid']; //will echo 8
?>
Edit:
Just saw your above post, you want to do something like this:

Code: Select all

http://www.example.com/forum.php?page=home
then in the PHP you can have something like:

Code: Select all

<?php
if($_GET['page'] == "home")
{
  include("includes/home.php");
  //OR
  // put all HTML inside these brackets
}
?>

Posted: Wed Dec 03, 2003 5:24 pm
by dull1554
ok, i think that helps, yeah thats what you call them, super, thanks

Posted: Wed Dec 03, 2003 6:47 pm
by Nay
Actually, just a tip, like IPB or phpBB, you should have a showforums.php and showtopic.php just to keep the mess a little more tidy. You'd somewhat go around:

// show forums (list all if none selected)

Code: Select all

<?php

$forum = $_GET['forum'];

// check if forum exists
$sql = "SELECT id FROM forums WHERE id = '$forum'";
$res = mysql_query($sql, $connection) or die(mysql_error());
$nrc = mysql_num_rows($res);

if(isSet($forum) && !empty($forum) && is_numeric($forum) && $nrc == 1):

// show the forum

else:

// show the lists of all forums

endif;

?>
Hope it helps, let me know how the forum goes.

-Nay

Posted: Wed Dec 03, 2003 8:45 pm
by dull1554
i got it all figured out, but i have another question regarding an error that i'm getting, i'll put that on a different topic

Posted: Thu Dec 04, 2003 1:07 am
by basdog22
I know this post is over but look at my way:

Code: Select all

<a href="index.php?op=home">Home</a>


Index.php:

<?php
include "$op.php"; // $op holds home. So $op.php is home.php
?>

That way there is no way you direct somewhere else.
You can even pass variables to home.php like:

<a href="index.php?op=home&do=view">Home</a>

Posted: Thu Dec 04, 2003 1:53 am
by Nay
HOLD it there. If you do that some one can just do a:

index.php?op=/var/www/httpd/httpd.conf

Doing, that PHP will include that file, meaning that the user will be able to see your httpd.conf. Not only httpd.conf, maybe your other files as well. So it's best to do:

index.php?op=home

Code: Select all

<?php

$op = $_GET['op']; // you can't use your way when registered_globals are off

// then

$allowed = array("home", "about");
if(in_array($op, $allowed)):
include $op . ".php";
else:
echo "you can't view that file";
exit;
endif;

// or

if($op == "home"):
include "home.php";

elseif($op == "about"):
include "about.php";

else:
echo "you can't do that";
exit;
endif;

?>
They're even more ways with CASE and other statements. Your code is not wrong but it's just a big security risk.

-Nay

Posted: Thu Dec 04, 2003 2:39 pm
by dull1554
thanks everyone, i have a few other parts of my forum that i'm working on, but as soon as im finished i'll post a url so u guys can go see/use it

Posted: Thu Dec 04, 2003 2:53 pm
by Sevengraff
you can do something like this:

stuff.php?dothis

Code: Select all

if( isset($_GET['dothis']) ) {
     echo "I am doing stuff";
}
but it's not very expandable. the way you want it to work, you'd have to look at $_SERVER['QUERY_STRING'], and maybe do something like this:

forum.php?thread1

Code: Select all

if( strpos($_SERVER['QUERY_STRING'], 'thread1')) {
    $thread_id = substr($_SERVER['QUERY_STRING'], 6);
     echo "Viewing thread: $thread_id";
}
It's a lot easier just to do forum.php?thread=1

Posted: Thu Dec 04, 2003 3:23 pm
by basdog22
HOLD it there. If you do that some one can just do a:

index.php?op=/var/www/httpd/httpd.conf

Doing, that PHP will include that file, meaning


:D
No.
You see what ever the index.php?op=...be it will end up with a .php extension. So index.php?op=/var/www/httpd/httpd.conf

will become: index.php?op=/var/www/httpd/httpd.conf.php

No file.. No inclusion

Correct me if i am wrong... :!: