forum.php?linkhere

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

forum.php?linkhere

Post 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!
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

any help would be awesome
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

could you be a lil more descriptive of your problem?

not really getting what u want.. :|
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post 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
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post 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
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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
}
?>
Last edited by DuFF on Wed Dec 03, 2003 5:25 pm, edited 1 time in total.
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

ok, i think that helps, yeah thats what you call them, super, thanks
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post 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
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

Post 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>
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post 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
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post 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
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

Post 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... :!:
Post Reply