Shoutbox

PHP Help Wanted (how do I do this: page.php?section=something) - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: PHP Help Wanted (how do I do this: page.php?section=something) (/showthread.php?tid=45715)

PHP Help Wanted (how do I do this: page.php?section=something) by rav0 on 06-03-2005 at 04:41 AM

PHP newbie alert

Often, I see websites that link to the other pages by linking to the same PHP file, but adding different queries. Example: This forum. Every thread is requested from the same showthread.php, but with a different query like ?tid=45715.

How do I do this?

Hope that makes sense. If not, please ask me to clarify.


RE: PHP Help Wanted (how do I do this: page.php?section=something) by -dt- on 06-03-2005 at 05:06 AM

well this forum uses the tid get value to know what thread to grab from the database , but i think you want to use something really simple like

code:
<?php
$x = isset($_GET['page']) ? $_GET['page'] : 'home';
if($x=='about'){?>
<--- about page html here --->

<? }else if($x=='other'){ ?>

<--- other page html here --->

<?}else{?>

<--- defult page html here --->
<? }?>


so say if someone goes to your page blah.php?page=about it will show <--- about page html here --->
thats for a really simple one though...

RE: RE: PHP Help Wanted (how do I do this: page.php?section=something) by rav0 on 06-03-2005 at 05:38 AM

Yes, that's what I wanted, not using my database. Thank you. Have a cookie [Image: cookie.gif]. Hmmm ... that cookie doesn't look that great, have a drumstick as well [Image: drumstick.gif]. I think that I'll use it with  $_REQUEST instaed of $_GET.

[off topic]
Is there a bit of myCode equivalant to <pre>?
[/pff topic]

If the file gets really big, will it slow down the site?

Guido, we need yummy-looking cookies :@:P.

Update: Yay, now I forgot         where I wanted to use this :(.
Update: Yay, now I remember     where I wanted to use this :). Where are my Post-its?


RE: PHP Help Wanted (how do I do this: page.php?section=something) by RaceProUK on 06-03-2005 at 07:09 AM

If the file gets really big, it might slow the server slightly.

And the closest to a BBcode equivalent of <pre> is [code].[/code]


RE: PHP Help Wanted (how do I do this: page.php?section=something) by saralk on 06-03-2005 at 09:02 AM

I would do something like this...

code:
<header>
<?php
if (!$a) { $a = "home"; }

include $a.".txt";
?>
<footer>

then have a file for each page, so index.php?a=links would load links.txt in the middle of the page. This way is better i think because you can add new pages without changing the main file.
RE: PHP Help Wanted (how do I do this: page.php?section=something) by Yousef on 06-03-2005 at 09:07 AM

quote:
Originally posted by saralk
I would do something like this...

code:
<header>
<?php
if (!$a) { $a = "home"; }

include $a.".txt";
?>
<footer>

then have a file for each page, so index.php?a=links would load links.txt in the middle of the page. This way is better i think because you can add new pages without changing the main file.

It's dangerous to do that. What if I browse to page.php?a=../some_passwd_file
The visitor will be able to access a lot of private files on the server when you use the way saralk suggested, you should build in a protection at least.
RE: PHP Help Wanted (how do I do this: page.php?section=something) by Ezra on 06-03-2005 at 09:13 AM

you should put those files in another folder, then they could only do that if they use ../

code:
<header>
<?php
if (!$a) { $a = "home"; }

include somefolder.$a.".txt";
?>
<footer>

RE: PHP Help Wanted (how do I do this: page.php?section=something) by Yousef on 06-03-2005 at 09:19 AM

quote:
Originally posted by Ezra
you should put those files in another folder, then they could only do that if they use ../
/www/specialfolder/../../ will still point to /
RE: PHP Help Wanted (how do I do this: page.php?section=something) by Ezra on 06-03-2005 at 09:21 AM

I use it on my website too, I have it like this

I hope it's secure else tell me how to make it better :D

code:
function pagina ($page){
   $pad = "paginas/".$page.".php";
   if(!file_exists($pad))
   {
      include("paginas/notfound.php");
   }
   else
   {
      include($pad);
   }
}
if(!isset($_GET["pagina"]) OR $_GET["pagina"] == "")
{
   pagina("home");
}
else
{
   pagina($_GET["pagina"]);
}


Edit: Automatic coloring would be nice :P
RE: PHP Help Wanted (how do I do this: page.php?section=something) by Stigmata on 06-03-2005 at 09:35 AM

ive always done it like this:

code:
<?php
$page = htmlentities($_GET['page']) ;
if (!isset($_GET['page'])) {
include ("home.php");
}
else {
$filename = "pages/$page.php";
if (file_exists($filename)) {   
include("pages/$page.php"); }
else {   
echo "Sorry, The Page Cannot Be Found";}
}
?>


RE: PHP Help Wanted (how do I do this: page.php?section=something) by rav0 on 06-03-2005 at 10:57 AM

Just to clear up:

Does the "!" used in some of those make things negative/false?

What does the "." that is used in some of your suggestions do?

quote:
Originally posted by rav0
PHP newbie alert


RE: PHP Help Wanted (how do I do this: page.php?section=something) by Dempsey on 06-03-2005 at 11:05 AM

quote:
Originally posted by rav0
Does the "!" used in some of those make things negative/false?
yea it means NOT   so !=  is not equals to

quote:
Originally posted by rav0
What does the "." that us used in some of your suggestions do?
"fish" . "cheese"

would make fishcheese

. appends variables/text together
RE: PHP Help Wanted (how do I do this: page.php?section=something) by KeyStorm on 06-03-2005 at 11:21 AM

quote:
Originally posted by rav0
Does the "!" used in some of those make things negative/false?

!$a also makes it false. Ie if $a contains 'true', some text, or a number but 0 it will become 'false'.

It's always good to make $a = NULL at the beginning to quickly ensure the _REQUEST values don't get mixed with your $a in some configs.
RE: PHP Help Wanted (how do I do this: page.php?section=something) by rav0 on 06-03-2005 at 11:23 AM

So is this PHP:

code:
echo 'some text'.$variable

the same as this JavaScript:

code:
document.writeln ('some text' + variable)

RE: RE: PHP Help Wanted (how do I do this: page.php?section=something) by Dempsey on 06-03-2005 at 11:25 AM

quote:
Originally posted by rav0
So is this PHP:

code:
echo 'some text'.$variable

the same as this JavaScript:

code:
document.writeln ('some text' + variable)

yea except you need a semi colon at the end of the php

code:
echo 'some text'.$variable;

RE: RE: RE: PHP Help Wanted (how do I do this: page.php?section=something) by rav0 on 06-03-2005 at 11:26 AM

quote:
Originally posted by Dempsey
yea except you need a semi colon at the end of the php

Hmmm ... I always forget those :$. There should be one at the end of the JavaScript as well.
RE: PHP Help Wanted (how do I do this: page.php?section=something) by KeyStorm on 06-03-2005 at 11:33 AM

And except javascript runs on the browser, leaving all the execution in hands of the viewer and PHP runs on the server, hidden to all.

But the effect might be the same, yeah.