?p=blah thingy
Moderator: General Moderators
?p=blah thingy
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....
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....
- Saethyr
- Forum Contributor
- Posts: 182
- Joined: Thu Sep 25, 2003 9:21 am
- Location: Wichita, Kansas USA
- Contact:
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.
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.
you can use like:
now, all you have todo is link to your pages like
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.
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.
?>Code: Select all
<?php
echo '<a href="'.$_SERVER['PHP_SELF'].'">Services</a>';
?>i have't tested it, post here if you need more help.
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...
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...
I'm using qads example; Yes, instead of include($page) you can echo out different content.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?
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)
}Again, using qads example; By using include($page) you can put the pages whereever you want. Just add a path before the pagename as;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?
Code: Select all
include('myhtml/'.$page);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.as u can seeim still abit confussed...
Happy coding.
that's what that example is trying to say.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?
you could do something like
Code: Select all
echo '<html><title><head>Hello</head></title><body>Hello there</body></html>';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
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
<?phpchange
to
check out [php_man]in_array[/php_man] if you want to learn more.
Code: Select all
<?php
if(in_array($valid, $page))
?>Code: Select all
<?php
if(in_array($page, $valid))
?>-
TheDeath2k4
- Forum Newbie
- Posts: 5
- Joined: Wed Dec 10, 2003 8:07 pm
- Location: somewhere....nowhere.....
- Contact:
heres how i did it
there
works for me
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");
}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
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
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?
thereworks for me
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.
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.