Free Web Hosting Forum
Go Back   Free Web Hosting Forum > Website Building > Web Programming
Reload this Page Page on Page, but with ?blahblah in url??
Reply
 
Thread Tools Display Modes
(#1 (permalink))
Old
AKSoapy29's Avatar
Member
AKSoapy29 is on a distinguished road
 
Posts: 63
Join Date: Apr 2011
Question 04-24-2012, 10:05 PM

Hello, I am creating a new website, and it will have a page in a page type think, and I was wondering how to do it, but the url needs to have a link to the page. Ex:

Main page shows all pages in it.
www.website.com can be out subject here

So if I want to view the other webpage inside this one, how would I make the url be like:
www.website.com rest of url here

I have seen it before like this:
www.website.com?page
and that only changes one thing in the page, which is what I want to do.


[2 minutes later]


Here is an old example, and I have already changed the design. Notice how the url stays the same, but the page is different.

http://aksoapy29.comoj.com/NewWebsiteTest/index.html

Last edited by d3iti; 04-25-2012 at 07:22 AM.
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
Shadowrider50's Avatar
Member
Shadowrider50 is on a distinguished road
 
Posts: 76
Join Date: Jan 2012
Default 04-25-2012, 01:00 AM

i am a little confused but do you want something like this:
www.example.com/?page=main //your main page
www.example.com/?page=contact //your contact page (i'm using contact as an example only)

Something like that the template of your page stays the same but the content is different.

What you could do is have index.php be the file where you put your template, css and everything.

You could use $_GET and a case switch (for security) to fetch the content of each page.

You could either have the html content in the script itself or you could put the html content in seperate files which you can use include or require with.

Here is an example:

switch ($_GET['page']){

/* Content to show if ?page=main */
case "main":
echo "<h2>content main</h2>";
break;

/* ?page=contact */
case "contact":
echo "<h2>content contact</h2>";
break;

/* ?page=about */
case "about":
echo "<h2>content about</h2>";
break;

Just add more or change it to your liking and in the echo you can put your content, have your template on the same page.
Reply With Quote
(#3 (permalink))
Old
AKSoapy29's Avatar
Member
AKSoapy29 is on a distinguished road
 
Posts: 63
Join Date: Apr 2011
Default 04-25-2012, 01:17 AM

Yeah, the /?page thing. But I am a little confused on how to create it. On a side note, would I have to create a new line for every new page I upload? And could I display an html file somewhere on the page with the /?page thing as guidance for the scripts?
Reply With Quote
(#4 (permalink))
Old
Junior Member
mhutti1 is on a distinguished road
 
Posts: 21
Join Date: Apr 2012
Default 04-25-2012, 08:01 PM

You could store the individual pages in a sql server then connect to that to get the pages content. Also a page system is good because you only have to do the main design once because you put the html with the content in it inside the main template of the site.
Some helpful php code:
PHP Code:
$page $_GET['page'];
mysql_connect("SERVER","USERNAME","PASSWORD");
mysql_select_db("DATABASE");
 
$query mysql_query("SELECT * FROM pages WHERE page='$page'");
 
    
$numrows mysql_num_rows($query);
 
    if(
$numrows !=0)
    {
        while (
$row mysql_fetch_assoc($query))
        {
            
$dbcontent $row['content'];
            
$dbtitle $row['title'];
        }

echo 
$dbtitle;
echo 
$dbcontent
To link to another page use
HTML Code:
<a href="page.php?page=Page to go to">Name</a>

Last edited by mhutti1; 04-25-2012 at 08:05 PM.
Reply With Quote
(#5 (permalink))
Old
AKSoapy29's Avatar
Member
AKSoapy29 is on a distinguished road
 
Posts: 63
Join Date: Apr 2011
Default 04-25-2012, 08:23 PM

Is there a way to do it without a sql server?
Like:

public_html >
main template.?
Pages >
Page1 >
contents.html
Images >
img1.jpg
img2.png
Page2 >
contents.html
...

And so on and so forth, and have the main template be html and php?

Just like the link I have above. The pages are in there own folders, and the main page calls them and displays them, but the link stays the same. All I would like to do is make sure the like changes with the page, but the template doesn't. I just don't want to re-program the headers and such each time, make it easy to use.

Last edited by AKSoapy29; 04-25-2012 at 08:26 PM.
Reply With Quote
(#6 (permalink))
Old
Junior Member
mhutti1 is on a distinguished road
 
Posts: 21
Join Date: Apr 2012
Default 04-25-2012, 09:10 PM

Yes if you use:
PHP Code:
$page=$_GET['page'].".php";
 include(
$page); 
Reply With Quote
(#7 (permalink))
Old
AKSoapy29's Avatar
Member
AKSoapy29 is on a distinguished road
 
Posts: 63
Join Date: Apr 2011
Default 04-25-2012, 09:19 PM

Alright. I tried this code, and it didn't work:

PHP Code:
<?php
$page
=$_GET['page'];
echo 
$page;
?>
Here is the link: http://aksoapy29.comoj.com/PHPTEST
and if you add anything like /?sdfgsdfh to the end, it doesn't do anything.

Last edited by AKSoapy29; 04-25-2012 at 09:23 PM.
Reply With Quote
(#8 (permalink))
Old
AKSoapy29's Avatar
Member
AKSoapy29 is on a distinguished road
 
Posts: 63
Join Date: Apr 2011
Default 04-25-2012, 09:44 PM

Something tells me I wasn't doing the php right. I saved it as index.php to. Does anyone that knows php more than I do know what is wrong?

Last edited by AKSoapy29; 04-26-2012 at 01:24 AM.
Reply With Quote
(#9 (permalink))
Old
Shadowrider50's Avatar
Member
Shadowrider50 is on a distinguished road
 
Posts: 76
Join Date: Jan 2012
Default 04-26-2012, 05:05 AM

Using include can pose some risks sometimes so i always recommend validation.

To automatically do it and still have verification you could get a file listing
PHP Code:
<?php
$documentfolder 
'/'//Put the folder where your documents are located here
$directory array_flip(scandir($documentfolder)); // scan the files & lists them
if (($_GET['page']) && (isset($directory["$_GET['page']"]))){ //verifies file
include $documentfolder $_GET['page']; //include the file
else { echo "404 Page Not Found"; } // error if not found
?>
you would use it like, example.com/index.php?page=test.php

I haven't tested it so tell me any bugs
remember there should be a file test.php in the $documentfolder for it to work with that example url

Last edited by Shadowrider50; 04-26-2012 at 05:09 AM.
Reply With Quote
(#10 (permalink))
Old
AKSoapy29's Avatar
Member
AKSoapy29 is on a distinguished road
 
Posts: 63
Join Date: Apr 2011
Default 04-26-2012, 08:18 PM

This is the error I get:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/a6702070/public_html/PHPTEST/index.php on line 4
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com