Page 1 of 2
?p=blah thingy
Posted: Wed Dec 10, 2003 1:31 am
by C
hey all,
i am just about as "n00b-ish" as u can get at php, i started 10 minutes ago. lol. anyhoo, when i go to a site like
http://www.shiver7.com/?p=services i see that in the url boz in IE it displays "?p=services" instead of a html file like "/services.html". why/how does it do this?
remember, i am a noob so go slow so i can understand....
Posted: Wed Dec 10, 2003 8:34 am
by Saethyr
if you see
http://www.shiver7.com/?p=services
This is just a querystring that appends p=Yes to the default file in the directory. Such As
http://www.shiver7.com/index.php?p=services
Now query strings are used to pass information from page to page through the URL, while not the most secure thing in the world it does have it's uses.
Posted: Wed Dec 10, 2003 8:52 am
by qads
you can use like:
Code: Select all
<?php
function inc($page)
{
//list of pagesi n a array which are valid.
$valid[] = "services";
$valid[] = "About";
$valid[] = "Home";
$valid[] = "Contact_US";
if(in_array($valid, $page))
{
include($page);
}
else
{
echo "Page not found...";//if page is not found, it will show this msg.
}
}
//
$p = $_GET['p'];
if(empty($p))
{
$p = "home";//a page which user will see if $p is empty.
}
inc($p);//a function to make sure only the correct pages are loaded.
?>
now, all you have todo is link to your pages like
Code: Select all
<?php
echo '<a href="'.$_SERVER['PHP_SELF'].'">Services</a>';
?>
but make sure you havew the above code in that links page first. i.e. main.php would work fine.
i have't tested it, post here if you need more help.
Posted: Wed Dec 10, 2003 10:29 am
by C
so, if i use that code and save it as main.php and put a tag saying to include it on all the other pages?
but couldn't i make the index page look like that and just use the "echo" thing and add html?
and when i do either of the above were will the files be saved that will display when the user clicks on the ?p=services link?
as u can seeim still abit confussed...
Posted: Wed Dec 10, 2003 5:22 pm
by C
my client needs to know so *bump*
Posted: Wed Dec 10, 2003 6:51 pm
by JAM
C wrote:so, if i use that code and save it as main.php and put a tag saying to include it on all the other pages?
but couldn't i make the index page look like that and just use the "echo" thing and add html?
I'm using qads example; Yes, instead of include($page) you can echo out different content.
Code: Select all
if(in_array($valid, $page))
{
if ($page == 'foo') { echo 'The FOO page'; }
elseif ($page == 'bar') { echo 'The BAR page'; }
// etc, or by using the switch function (see manual)
}
and when i do either of the above were will the files be saved that will display when the user clicks on the ?p=services link?
Again, using qads example; By using include($page) you can put the pages whereever you want. Just add a path before the pagename as;
as u can seeim still abit confussed...
Yes, nothing wrong with asking, but instead of bumping the post, try reading the manual if you want to learn. If you do not want to learn, make a post in the Work-section of this board and someone might help you more.
Happy coding.
Posted: Wed Dec 10, 2003 7:05 pm
by C
where it says { echo 'The FOO page'; } in the if ($page == 'foo') { echo 'The FOO page'; } line i can just change the text "The home page" to normal html?
Posted: Wed Dec 10, 2003 7:10 pm
by infolock
C wrote:where it says { echo 'The FOO page'; } in the if ($page == 'foo') { echo 'The FOO page'; } line i can just change the text "The home page" to normal html?
that's what that example is trying to say.
you could do something like
Code: Select all
echo '<html><title><head>Hello</head></title><body>Hello there</body></html>';
or whatever else it is you want.
Posted: Wed Dec 10, 2003 7:27 pm
by C
ok, ur all grealty helping me out. thank you. but i have one more question/problem: when i go and try to use this code on my site i get the message "Warning: in_array(): Wrong datatype for second argument in /home/chrisbla/public_html/test.php on line 9
Page not found... ". now, that shouldn't happen cuz w/ the $valid[] = "home"; line i made it so the home instance should work.
anyhoo, this is the code that im using:
<?php
function inc($page)
{
//list of pagesi n a array which are valid.
$valid[] = "services";
$valid[] = "about";
$valid[] = "home";
$valid[] = "contact_us";
if(in_array($valid, $page))
{
if ($page == 'home') { echo 'The home page'; }
elseif ($page == 'about') { echo 'The about page'; }
include($page);
}
else
{
echo "Page not found...";//if page is not found, it will show this msg.
}
}
//
$p = $_GET['p'];
if(empty($p))
{
$p = "butter";//a page which user will see if $p is empty.
}
inc($p);//a function to make sure only the correct pages are loaded.
?>
u can see the test php file
http://chrisblau.com/test.php?p=home
Posted: Wed Dec 10, 2003 7:31 pm
by qads
change
Code: Select all
<?php
if(in_array($valid, $page))
?>
to
Code: Select all
<?php
if(in_array($page, $valid))
?>
check out [php_man]in_array[/php_man] if you want to learn more.
Posted: Wed Dec 10, 2003 8:07 pm
by TheDeath2k4
heres how i did it
Code: Select all
<?php
$page=$GET_ї'page'];
$indexcontent = "index content here";
$page1content = "page 1 content here";
$page2content = "page 2 content here";
if ($page == page1)
{
print("$page1content");
}
elseif ($page == page2)
{
print("$page2content");
}
else
{
print("indexcontent");
}
there

works for me
Posted: Wed Dec 10, 2003 8:16 pm
by qads
yep, thats a another way of doing it, i uselly dont do this at all, i just make a function to read contents of my pages dir, mark the file names as valid names in a array and when the user asks for a page, i check to see if it is in the array, if it is scripts includes it, if not it will include a error.php...
the main reason is that you can upload as many files as you like in the content dir, the script will update it self when reading the dir...very easy and painles

Posted: Wed Dec 10, 2003 8:38 pm
by C
TheDeath2k4 wrote:heres how i did it
Code: Select all
<?php
$page=$GET_ї'page'];
$indexcontent = "index content here";
$page1content = "page 1 content here";
$page2content = "page 2 content here";
if ($page == page1)
{
print("$page1content");
}
elseif ($page == page2)
{
print("$page2content");
}
else
{
print("indexcontent");
}
instead of print staments u could use echo statments and html code, right?
there

works for me
Posted: Wed Dec 10, 2003 8:43 pm
by m3mn0n
I use a series of [php_man]switch[/php_man]() cases that [php_man]require_once[/php_man]() a page when one is called.
Posted: Wed Dec 10, 2003 8:55 pm
by C
well, i got it. i was using quads' code and it basicly worked but it did not like the "include($page);" line...but now it works! thanks all!
now, fo one more question: like alot of webdesigners i make the layout for my page in photoshop, then export it and all it's slices with an index.html file. then i edit the html file and add all the javascript and extra stuff.
now that i'll be using the "echo" tag to put in the html to the php file will i have to add the "echo" tag to each line of html that i export from photoshop? or is there an programm that will do it for me?
also, i use right click restrict scripts on my website so people can't steal my images (unless they use Opera...grrr...). how do i incorpoate the javascript right click restrict scripts into the php? just cut and past it in? or do i use echo tags?
thank you all so much.