Log in

View Full Version : What's wrong with this?



Black_Apalachi
20-07-2009, 01:58 AM
Ok I've tried a few different things and spent the last couple of hours looking at tutorials on Google and on the forum but they all say the same thing which doesn't resolve the problem.

Basically my php includes won't work. I am now able to see my homepage's content but any link I click just stays with the homepage's content instead of its respective content.


Here is my navigation menu:


&raquo; <a href="index.php">Home</a> <br />
&raquo; <a href="index.php?p=news">News</a> <br />
&raquo; <a href="index.php?p=values">Classic Rare Values</a> <br />
&raquo; <a href="index.php?p=guides">Guides</a> <br />
&raquo; <a href="index.php?p=knowledge">Knowledge</a> <br />
&raquo; <a href="index.php?p=links">Links</a> <br />
And here is my include which is in the content section of my index file:


<?php
$_GET['page'];
if($page == "home")
{
include('home.php');
}
elseif($page == "news")
{
include('news.php');
}
elseif($page == "values")
{
include('values.php');
}
elseif($page == "guides")
{
include('guides.php');
}
elseif($page == "knowledge")
{
include('knowledge.php');
}
elseif($page == "links")
{
include('links.php');
}
else
{
include('home.php');
}

?>If anyone can spot the error, it'd be wonderful :D.

Agnostic Bear
20-07-2009, 02:02 AM
If you read the other page, you would have seen it was solved already.


change $_GET['page'] to $page = $_GET['page'];

Dentafrice
20-07-2009, 02:03 AM
Why don't you just do something similar to this:



<?php

$page = $_GET["page"];
$page = "{$page}.php";

if(!file_exists($page)) {
include "404.php";
} else {
include $page;
}

?>

Black_Apalachi
20-07-2009, 02:06 AM
Doesn't work.

And I did read everything in the other thread, I just don't get where people mean for stuff to go sometimes.

Edit @Dentafrice: I don't understand how to apply that...

Dentafrice
20-07-2009, 02:13 AM
Post your whole page code..

Black_Apalachi
20-07-2009, 02:15 AM
lol OK :P.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-

transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="Keywords" content="Free,Xhtml,css,div,coded,layout,habbox,--ss--,shane" />
<meta name="Description" content="A free fully coded sleek Habbo layout" />
<title>Robald</title>
<style type="text/css">
/* Thanks to --ss-- for layout and original coding.*/
body {
font-family: Verdana;
font-size: 10px;
font-weight: normal;
background-color: ;
background-image: url(images/bg_grey.PNG);
text-align: left;
margin-top: 10px;
margin-bottom: 10px;
margin-left: auto;
margin-right: auto;
}
#container {
width: 858px;
margin: auto;
overflow: hidden;
}
#banner {
width: 858px;
height: 100px;
background-image: url(images/banner.gif);
}
#middle {
background-image: url(images/strip.PNG);
overflow: hidden;
}
#footer {
height: 8px;
background-image: url(images/footer.gif);
}
#left {
width: 210px;
float: left;
}
#right {
width: 648px;
float: left;
}
#tittle {
width: 98%;
border-bottom: 1px solid #FF9900;
color: #FF9900;
font-weight: bold;
padding: 5px;
}
#content {
color: #808080;
padding: 5px;
overflow: hidden;
}
#content a {
color: #808080;
text-decoration: none;
font-weight: bold;
}
#content a:hover {
color: #999999;
text-decoration: none;
font-weight: bold;
}
.box_bot {
height: 10px;
background-image: url(images/bot.gif);
}
#nav {
width: 200px;
margin-left: auto;
margin-right: auto;
margin-top: 5px;
}
#nav_top {
height: 22px;
background-image: url(header.php?t=NAVIGATION);
}
#nav_mid {
background-image: url(images/mid.PNG);
padding: 5px;
}
#nav_mid A:link
{ color: #81467D; text-decoration: none; }
#nav_mid A:visited
{ color: #81467D; text-decoration: none; }
#nav_mid A:active
{ color: #81467D; text-decoration: none; }
#nav_mid A:hover
{ color: #FF9900; text-decoration: none; }
#news {
width: 200px;
margin-left: auto;
margin-right: auto;
margin-top: 5px;
color: #723D6D;
}
#news_top {
height: 22px;
background-image: url(header.php?t=HEADLINES);
}
#news_mid {
background-image: url(images/mid.PNG);
padding: 5px;
}
#news_mid A:link
{ color: #81467D; text-decoration: none; }
#news_mid A:visited
{ color: #81467D; text-decoration: none; }
#news_mid A:active
{ color: #81467D; text-decoration: none; }
#news_mid A:hover
{ color: #FF9900; text-decoration: none; }
#feature {
width: 200px;
margin-left: auto;
margin-right: auto;
margin-top: 5px;
color: #723D6D;
}
#feature_top {
height: 22px;
background-image: url(header.php?t=JOIN%20US);
}
#feature_mid {
background-image: url(images/mid.PNG);
padding: 5px;
}
#feature_mid A:link
{ color: #81467D; text-decoration: none; }
#feature_mid A:visited
{ color: #81467D; text-decoration: none; }
#feature_mid A:active
{ color: #81467D; text-decoration: none; }
#feature_mid A:hover
{ color: #FF9900; text-decoration: none; }
#disclaimer {
width: 200px;
margin-left: auto;
margin-right: auto;
margin-top: 5px;
text-align: center;
}
#disclaimer A:link
{ color: #502B4D; text-decoration: none; }
#disclaimer A:visited
{ color: #502B4D; text-decoration: none; }
#disclaimer A:active
{ color: #502B4D; text-decoration: none; }
#disclaimer A:hover
{ color: #3F223E; text-decoration: none; }
/* Dummy Images */
.laptop {
height: 62px;
width: 62px;
background-image: url(images/laptop.gif);
float: right;
margin-left: 3px;
margin-right: 3px;
}
.image1 {
height: 121px;
width: 131px;
background-image: url(images/image1.gif);
float: right;
margin-top: 2px;
margin-right: 4px;
}
.image2 {
height: 89px;
width: 61px;
background-image: url(images/image2.gif);
float: left;
margin-top: 2px;
margin-left: 3px;
margin-right: 3px;
}
-->
</style>
</head>

<body>
<div id="container">
<div id="banner"></div>
<div id="middle">
<div id="left">
<div id="nav">
<div id="nav_top"></div>
<div id="nav_mid">
<!-- Start nav bar -->
&raquo; <a href="index.php">Home</a> <br />
&raquo; <a href="index.php?p=news">News</a> <br />
&raquo; <a href="index.php?p=values">Classic Rare Values</a> <br />
&raquo; <a href="index.php?p=guides">Guides</a> <br />
&raquo; <a href="index.php?p=knowledge">Knowledge</a> <br />
&raquo; <a href="index.php?p=links">Links</a> <br />
<!-- End navigation -->
</div>
<div class="box_bot"></div>
</div>
<div id="news">
<div id="news_top"></div>
<div id="news_mid">
<!-- Start news -->
<div class="laptop"></div>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Proin non ipsum vestibulum est elementum mollis. Mauris

placerat velit vestibulum lacus.<br />
Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.
<!-- End news -->
</div>
<div class="box_bot"></div>
</div>

<div id="feature">
<div id="feature_top"></div>
<div id="feature_mid">
<!-- Start Feature -->

For even more opportunities to get involved, win some great prizes and get your very own Blabbo badge, join

the <a href="www.habbo.co.uk"><b>Blabbo Group</b></a> today!

<!-- End Feature -->
</div>
<div class="box_bot"></div>
</div>
<div id="disclaimer">

<!-- Disclaimer info -->

<FONT COLOR="#502B4D">
Thanks to <a href="www.habbo.co.uk/homes/--ss--"><b>--ss--</b></a> for design.<br/><br/>
© BLABBO.net
</FONT>

<!-- End Disclaimer info -->
</div>

</div>
<div id="right">
<div id="tittle" align="left"><MARQUEE direction="left" loop="20" width="100%">
<STRONG>Welcome to BLABBO.net!</STRONG></MARQUEE></div>
<div id="content">

<!-- Start Main Content -->



<?php
$page = $_GET['page'];
if($page == "home")
{
include('home.php');
}
elseif($page == "news")
{
include('news.php');
}
elseif($page == "values")
{
include('values.php');
}
elseif($page == "guides")
{
include('guides.php');
}
elseif($page == "knowledge")
{
include('knowledge.php');
}
elseif($page == "links")
{
include('links.php');
}
else
{
include('home.php');
}

?>


<!-- End Content -->


</div>
</div>
</div>
<div id="footer"></div>
</div>
</body>

</html>

Iszak
20-07-2009, 02:22 AM
It's because you're also accessing $_GET['page'] and not $_GET['p'] (as you're using ?p=name as opposed to ?page=name) so either modify the links or modify the key and it should work.

Black_Apalachi
20-07-2009, 02:26 AM
It's because you're also accessing $_GET['page'] and not $_GET['p'] (as you're using ?p=name as opposed to ?page=name) so either modify the links or modify the key and it should work.

I <3 U +rep :8.

RastaLulz
20-07-2009, 02:33 AM
Doesn't work.

And I did read everything in the other thread, I just don't get where people mean for stuff to go sometimes.

Edit @Dentafrice: I don't understand how to apply that...
It works the same way as the code you're using.. Besides the fact that it's much cleaner, and easier to use.

Dentafrice
20-07-2009, 02:35 AM
Just put my code, where your PHP code is.

Black_Apalachi
20-07-2009, 02:36 AM
It works the same way as the code you're using.. Besides the fact that it's much cleaner, and easier to use.

well are the red parts what are supposed to be edited with the appropriate file names?

Dentafrice
20-07-2009, 02:41 AM
No.. you don't edit anything..

RastaLulz
20-07-2009, 02:41 AM
well are the red parts what are supposed to be edited with the appropriate file names?
In the code Dentafrice (http://www.habboxforum.com/member.php?u=48188) posted, you don't edit a thing, you simply put it into your layout where you want your content, and use the url:
http://www.yourwebsite.com/index.php?page=(page)

It's better than having to edit the php script that you have everytime you have a new page.

Black_Apalachi
20-07-2009, 02:44 AM
Oh OK, thanks. It just confused me not having to tell it what the files were etc :P.

Dentafrice
20-07-2009, 02:47 AM
You get that from the variable.

Black_Apalachi
20-07-2009, 01:46 PM
The only thing now is, when I go to http://localhost/site/ it shows the 404 error in the content area instead of my homepage content. It only shows the homepage once I click 'Home' on the nav.

Is there a default setting I can add to that code or something?



<?php

$page = $_GET["p"];
$page = "{$page}.php";

if(!file_exists($page)) {
include "404.php";
} else {
include $page;
}

?>

Dentafrice
20-07-2009, 01:56 PM
<?php

$page = $_GET["p"];
$page = ($page == '') ? 'home' : $page;
$page = "{$page}.php";

if(!file_exists($page)) {
include "404.php";
} else {
include $page;
}

?>

Black_Apalachi
20-07-2009, 01:58 PM
thank you sir :).

Dentafrice
20-07-2009, 01:59 PM
Edit the part that says home for the page you want.

Black_Apalachi
20-07-2009, 02:01 PM
home is exactly what I want ;) I'll owe you about 3 reps lol

Dentafrice
20-07-2009, 02:02 PM
haha it's fine ;P

Agnostic Bear
20-07-2009, 02:26 PM
Gonna go ahead and make that code strict compatible.



<?php
$page = ( isset( $_GET['p'] ) === true and $_GET['p'] !== '' ) ? $_GET['p'] . '.php' : 'home';
( !file_exists( $page ) ) ? include '404.php' : include $page;
?>

Immenseman
20-07-2009, 02:58 PM
+repped him for you rob my lad, beats 3 of yours anyway :P xx

Dentafrice
20-07-2009, 04:02 PM
Gonna go ahead and make that code strict compatible.



<?php
$page = ( isset( $_GET['p'] ) === true and $_GET['p'] !== '' ) ? $_GET['p'] . '.php' : 'home';
( !file_exists( $page ) ) ? include '404.php' : include $page;
?>

You're not adding .php to home though.

@Jake: thank ya babezz :]

Black_Apalachi
20-07-2009, 04:14 PM
It's OK thanks. As long as it's working fine I don't wanna mess wth it lol


+repped him for you rob my lad, beats 3 of yours anyway :P xx

hahahaha nice one Jake :P +rep for you too :D.

Agnostic Bear
20-07-2009, 07:19 PM
You're not adding .php to home though.

@Jake: thank ya babezz :]



<?php
$page = ( isset( $_GET['p'] ) === true and $_GET['p'] !== '' ) ? $_GET['p'] . '.php' : 'home.php';
( !file_exists( $page ) ) ? include '404.php' : include $page;
?>

Want to hide these adverts? Register an account for free!