?p=blah thingy

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

C
Forum Newbie
Posts: 14
Joined: Wed Dec 10, 2003 1:31 am

?p=blah thingy

Post 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....
User avatar
Saethyr
Forum Contributor
Posts: 182
Joined: Thu Sep 25, 2003 9:21 am
Location: Wichita, Kansas USA
Contact:

Post 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.
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post 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.
C
Forum Newbie
Posts: 14
Joined: Wed Dec 10, 2003 1:31 am

Post 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...
C
Forum Newbie
Posts: 14
Joined: Wed Dec 10, 2003 1:31 am

Post by C »

my client needs to know so *bump*
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post 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;

Code: Select all

include('myhtml/'.$page);
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.
C
Forum Newbie
Posts: 14
Joined: Wed Dec 10, 2003 1:31 am

Post 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?
User avatar
infolock
DevNet Resident
Posts: 1708
Joined: Wed Sep 25, 2002 7:47 pm

Post 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 '&lt;html&gt;&lt;title&gt;&lt;head&gt;Hello&lt;/head&gt;&lt;/title&gt;&lt;body&gt;Hello there&lt;/body&gt;&lt;/html&gt;';
or whatever else it is you want.
C
Forum Newbie
Posts: 14
Joined: Wed Dec 10, 2003 1:31 am

Post 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

Code: Select all

<?php
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post 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.
TheDeath2k4
Forum Newbie
Posts: 5
Joined: Wed Dec 10, 2003 8:07 pm
Location: somewhere....nowhere.....
Contact:

Post by TheDeath2k4 »

heres how i did it

Code: Select all

<?php
$page=$GET_&#1111;'page'];
$indexcontent = "index content here";
$page1content = "page 1 content here";
$page2content = "page 2 content here";
if ($page == page1)
&#123;
     print("$page1content");
&#125;
elseif ($page == page2)
&#123;
     print("$page2content");
&#125;
else
&#123;
    print("indexcontent");
&#125;
there :) works for me
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post 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 :D
C
Forum Newbie
Posts: 14
Joined: Wed Dec 10, 2003 1:31 am

Post by C »

TheDeath2k4 wrote:heres how i did it

Code: Select all

<?php
$page=$GET_&#1111;'page'];
$indexcontent = "index content here";
$page1content = "page 1 content here";
$page2content = "page 2 content here";
if ($page == page1)
&#123;
     print("$page1content");
&#125;
elseif ($page == page2)
&#123;
     print("$page2content");
&#125;
else
&#123;
    print("indexcontent");
&#125;

instead of print staments u could use echo statments and html code, right?
there :) works for me
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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.
Last edited by m3mn0n on Thu Dec 11, 2003 9:33 pm, edited 1 time in total.
C
Forum Newbie
Posts: 14
Joined: Wed Dec 10, 2003 1:31 am

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