PDA

View Full Version : help with php code



ozefrog
July 27th, 2001, 02:05
what code would i use in a php to make a page open at http://www.myhost.com/go.php?services

in other words have 3 or more pages in the 1 php script and if i wanted to open one page (the services page) point it to go.php?services ?

thanks

Jome
July 30th, 2001, 18:02
Hello,

you should use if-statements. Like this:

<?
if ($QUERY_STRING == "services") {
?>
<HTML>
This is my services page!
</HTML>
<?
} elseif ($QUERY_STRING == "contact") {
?>
This is my contact page!
<?
}
?>

..and so on.

lucifer
July 30th, 2001, 18:06
or use and have your pages saved seperately


<?
$page=$QUERY_STRING;
if ($page=="services" || $page=="nextpage"){
include "$page.html";
}
?>

jetalomar
August 2nd, 2001, 07:45
I want that code also. i want to convert my whole website to php

let' see i want to have it like http://mywebsite.com/index.php?page1
and http://mvpleague.com/com/index?page2 etc how do i do that?

ozefrog
August 2nd, 2001, 08:45
if you are planning on converting your site ot php, i reccomend that you base your site on templates. make a header and footer php doc then call them in each document, i did it to my site, its so easy to edit! plus if you use premade scripts, all you have to do is call the templates with 2 simply commands to match your site design! this technique saves me hours of workon my site.

jetalomar
August 2nd, 2001, 14:03
give me more details, i have all the template done, i just want to change it to php. also how do u call a ssi php from a .shtml

let's see i have this page http://mywebsite.com/links.shtml
and i want to put my leftnav.php in the left site how do i do it?
the ssi is not working for php

ozefrog
August 3rd, 2001, 10:09
i do not know how to call ssi in php, i know there is a way to do it, i have seen it somewhere.

but to call your header and footer templates, create a new php doc and lay it out like this

<?php include("http://mysite.com/header.php");?>

type html code in here

<?php include("http://mysite.com/footer.php");?>

save it then test it, simple!

keith
August 4th, 2001, 09:38
<html>
<head>
<title>My Page</title>
</head>

<body>

<?
if (!$QUERY_STRING) {
include("pages/home.php");
} else {
include("pages/$QUERY_STRING.php");
}
?>

</body>
</html>

then store all your files in a directory called /pages/

so when you link to "/go.php?links", it will grab the info from "/pages/links.php"

and if no query_string is specified, it will automatically print the source of "/pages/home.php"

jetalomar
August 4th, 2001, 14:19
my pages are on .shtml and i use a lot of ssi. will they work on php?

niv
August 4th, 2001, 14:37
if you're using/trying PHP, why use SSI? :confused::confused::confused:

jetalomar
August 4th, 2001, 15:39
i have a couple of pages on PHP but 90 % of my pages are .shtml and i want to changed them to php

niv
August 4th, 2001, 15:42
<!--- #include virtual="blah/blah/blah.txt" --->

or something like that, change it to:

<? include ("blah/blah/blah.txt"); ?>

jetalomar
August 4th, 2001, 15:55
i have php code on that page, if i change the extension to txt won't work, it will paste the code in the page.

niv
August 4th, 2001, 15:59
wha? :confused: reorganize those words and explain please :p

do you have php code in that txt file? then put <? and ?> around that code

jetalomar
August 4th, 2001, 16:08
you are not understanding me. i want to call to call this page, php.php to this one at html.shtml
but it doesn't work.
I put this code
<!--- #include virtual="php.php" --->

and it get this error, [an error occurred while processing this directive] like if the php page doesn't exist.

niv
August 4th, 2001, 16:11
you don't seem to be understanding me. why use SSI when:

1. you're trying to include a php page
2. you have php on your server

PHP/SSI is a horrible combination. Just go with PHP.

jetalomar
August 4th, 2001, 16:23
i want to display this page http://mvpleague.com/results/lastgame/bal.php on this one http://mvpleague.com/teams/orioles.shtml , under the schedule, but i removed the code cuz it wasn't loading that page there. so do u understand now?

niv
August 4th, 2001, 16:52
i understand but i'm just saying this is very very inefficient. you might as well incorporate it into one page.

Who?
August 4th, 2001, 18:17
the best way to do it is:

<?php
if(strstr($page, "..") || $page[0]=="/") $page = "";
if(empty($page)) $page = "news.txt";
else { $page = $page . ".php"; }
if(is_file("$page")){ include("$page");
} else echo "<b>404</b><br>We cant fined that page.";
?>

just put that code where you want the content to be, then to link to the page you do it like ?page=pagename and u dont need to put a .php on the end or for pages in other dir do ?page=dirname/pagename