PDA

View Full Version : Sorry....php question



The Red Guy
June 9th, 2002, 02:59
I want to know how can I have pages like http://www.domain.com/page.php?type=2 .

bigperm
June 9th, 2002, 03:43
There are a million threads about this.

biggulp
June 9th, 2002, 04:58
<?
if ($page == "2") {
include("yourfile.php");
} elseif ($page == "3") {
include("anotherfile.php");
}
?>

The Red Guy
June 10th, 2002, 04:12
What is it called? Probably I can find some related materials/

bigperm
June 10th, 2002, 04:38
To give it a name, I'd call it query string navagation, but I doubt you'd get any matches if you searched for it.

It's easy to do, and there are a million ways to do it.

The way I'd to it would be to have content in a mySQL table with an ID, and use the query string to pull the content by that ID.

That might be a little too advanced for some people so here is another option.

Create a template. No content. Make pages with your content and name them however you want to name them, by numbers or by name.

Then in your template where you want your content have:


<?
if ($page) {
include "path/to/your/content/$page";
}
else { include "path/to/default/content"; }
?>

The Red Guy
June 10th, 2002, 04:46
Originally posted by bigperm


Create a template. No content. Make pages with your content and name them however you want to name them, by numbers or by name.

Then in your template where you want your content have:


<?
if ($page) {
include "path/to/your/content/$page";
}
else { include "path/to/default/content"; }
?> 1) Can the content be *.shtml?
2) What does else { include "path/to/default/content"; }
do?

bigperm
June 10th, 2002, 04:58
Originally posted by The Red Guy
1) Can the content be *.shtml?
2) What does else { include "path/to/default/content"; }
do? 1) No. Not unless you modified your htaccess to parse shtml pages as php for some reason. PHP pages should be named *.php to be parsed.
2)That would be the path to what you want to be displayed if the file is called without and query strings.

The Red Guy
June 10th, 2002, 05:04
<?
if ($page) {
include "path/to/your/content/$page";
}
else { include "path/to/default/content"; }
?>
1) Then can I use php include instead?
2) path/to/your/content/$page - Must I replace the $page with my .php page?
3) Do you know where I can find this tutorial?

bigperm
June 10th, 2002, 05:22
Originally posted by The Red Guy

<?
if ($page) {
include "path/to/your/content/$page";
}
else { include "path/to/default/content"; }
?>
1) Then can I use php include instead?
2) path/to/your/content/$page - Must I replace the $page with my .php page?
3) Do you know where I can find this tutorial? 1) That is php include.
2)No. $page is a variable that is defined when you access the page like you said in your first post... index.php?page=whatever.ext
3)http://php.net :)

The Red Guy
June 10th, 2002, 06:01
Originally posted by bigperm
1) That is php include.
2)No. $page is a variable that is defined when you access the page like you said in your first post... index.php?page=whatever.ext
3)http://php.net :) 1)How do I link to that particular page?
2) Do you have that specific link to that tutorial? I've tried to find it at php.net but to no avail.

bigperm
June 10th, 2002, 06:31
Originally posted by The Red Guy
1)How do I link to that particular page?
2) Do you have that specific link to that tutorial? I've tried to find it at php.net but to no avail. 1)Which page are you talking about?
2)That link was a joke. There isn't a tutorial that I know of. I gave you the address of the homepage of the language.

Moonman
June 10th, 2002, 06:40
OK, say you have a file called john.php, and in that file you have
<?
if ($page == "2") {
include("yourfile.php");
} elseif ($page == "3") {
include("anotherfile.php");
}
?>
then when you go to www.test.com/john.php?page=2
it will show yourfile.php, but say you go to www.test.com/john.php?page=3
then it will show anotherfile.php

to change the john.php?page= bit you must edit
if ($page == "2") and change the page bit. like say you change the script above to
<?
if ($fred == "2") {
include("yourfile.php");
} elseif ($fred == "3") //notice i also changed the page bit here
{
include("anotherfile.php");
}
?>
and saved that file called john.php
then you went to www.test.com/john.php?fred=2
then it would show yourfile.php

but another bit of the code you can change is
if ($fred == "2")
like you can change that to
<?
if ($fred == "page2") {
include("yourfile.php");
} elseif ($fred == "page3") {
include("anotherfile.php");
}
?>
and again save that as john.php
when you go to www.test.com/john.php?fred=page2
it will go to yourfile.php,
but if you go to www.test.com/john.php?fred=page3
it will go to anotherfile.php

Understand? if not i will find a good tutorial to explain all this.

bigperm
June 10th, 2002, 07:07
That limits you to only 3 different content pages.

Moonman
June 10th, 2002, 07:13
you can add more easily, to add more to the following script
<?
if ($fred == "page2") {
include("yourfile.php");
} elseif ($fred == "page3") {
include("anotherfile.php");
}
?>
you would just add more of

elseif ($fred == "page3") {
include("anotherfile1.php");
}

so to have 5 pages of content (4 different ones, and the main one) you would use
<?
if ($fred == "page2") {
include("yourfile.php");
} elseif ($fred == "page3") {
include("anotherfile.php");
} elseif ($fred == "page4") {
include("anotherfile2.php");
} elseif ($fred == "page5") {
include("anotherfile3.php");
}
?>

bigperm
June 10th, 2002, 08:41
But why hard code the file names if you don't have to?

Moonman
June 10th, 2002, 08:56
Well look at it, it is still really simple.

AlieXai
June 10th, 2002, 16:22
> But why hard code the file names if you don't have to?

Security

bigperm
June 10th, 2002, 20:16
Originally posted by AlieXai
> But why hard code the file names if you don't have to?

Security If that's an issue, but store your content files below your httpdocs (or whatever) folder, use .htaccess to prevent unwanted lookers or you can use a DB. There's still no reason to hard code them.

The Red Guy
June 10th, 2002, 23:44
Originally posted by Moonman
OK, say you have a file called john.php, and in that file you have
<?
if ($page == "2") {
include("yourfile.php");
} elseif ($page == "3") {
include("anotherfile.php");
}
?>
then when you go to www.test.com/john.php?page=2
it will show yourfile.php, but say you go to www.test.com/john.php?page=3
then it will show anotherfile.php

to change the john.php?page= bit you must edit
if ($page == "2") and change the page bit. like say you change the script above to
<?
if ($fred == "2") {
include("yourfile.php");
} elseif ($fred == "3") //notice i also changed the page bit here
{
include("anotherfile.php");
}
?>
and saved that file called john.php
then you went to www.test.com/john.php?fred=2
then it would show yourfile.php

but another bit of the code you can change is
if ($fred == "2")
like you can change that to
<?
if ($fred == "page2") {
include("yourfile.php");
} elseif ($fred == "page3") {
include("anotherfile.php");
}
?>
and again save that as john.php
when you go to www.test.com/john.php?fred=page2
it will go to yourfile.php,
but if you go to www.test.com/john.php?fred=page3
it will go to anotherfile.php

Understand? if not i will find a good tutorial to explain all this. 1) Can I make the john.php as the front page instead of the john.php?page=2 ?
2) How do I link to that particular file if I need to? Let's say I have frontpage.php , how do I make a hyperlink?By linking to john.php?page=2 or yourfile.php directly?

dawizman
June 11th, 2002, 00:07
1.It is the front page
2.it would be <a href="john.php?page=2>link</a>

The Red Guy
June 11th, 2002, 00:32
Originally posted by dawizman
1.It is the front pageCan I insert content into john.php?

spec
June 11th, 2002, 02:54
This topic has come up in 4 threads now
www.clanhq.net/spec_index/index.php
if you want this easy to use and setup script for free just say so

Moonman
June 11th, 2002, 04:29
Originally posted by The Red Guy
1) Can I make the john.php as the front page instead of the john.php?page=2 ?

to make it index.php?page=2 all you have to do is open a blank file, put in the following code
<?
if ($page == "2") {
include("yourfile.php");
} elseif ($page == "3") {
include("anotherfile.php");
}
?>

then save that as index.php.

dawizman
June 11th, 2002, 08:42
Can I insert content into john.php?


Yes, as long as <?php and ?> are surrounding the php.

The Red Guy
June 11th, 2002, 23:47
Originally posted by dawizman

Yes, as long as <?php and ?> are surrounding the php. What do you mean by surrounding?


Qoriginally posted by Moonman

to make it index.php?page=2 all you have to do is open a blank file, put in the following code
<?
if ($page == "2") {
include("yourfile.php");
} elseif ($page == "3") {
include("anotherfile.php");
}
?>

then save that as index.php.

Can I do this:
<?
if ($id == "") {
include("yourfile.php");

Moonman
June 12th, 2002, 03:45
yup you sure can, so instead of whateverfilename.php?page=two it will be whateverfilename.php?id=

The Red Guy
June 12th, 2002, 05:00
Originally posted by Moonman
yup you sure can, so instead of whateverfilename.php?page=two it will be whateverfilename.php?id= Thanks, I've got it.

Moonman
June 12th, 2002, 06:16
No Probs.

The Red Guy
June 13th, 2002, 02:07
Sorry, just one more question. Is there a difference between
<?php
and
<?

Moonman
June 13th, 2002, 02:38
Sometimes some servers choke on <? and don't like it, thats why i much rather use <?php

The Red Guy
June 17th, 2002, 06:07
Can I make it index.php?id=1&code=11

With an extra &?

biggulp
June 17th, 2002, 06:43
why would you need the extra variable? don't use it unless you need it.

The Red Guy
June 17th, 2002, 07:42
Originally posted by biggulp
why would you need the extra variable? don't use it unless you need it. I have two topics, and I need to seperate it like one.php?view=gallery&page=2