Jump to content

Archived

This topic is now archived and is closed to further replies.

kriffer

help

Recommended Posts

im new to php, im just learnin this and css .. i tried to do somethig which i thought was simple but am having a problem with... ok heres the problem.. im makin a menu.. but the files arent coming up on the page when you click on the link so this is my menu
[code]<div id="navcontainer">
<ul id="navlist">
<li id="active"><a href="?" id="current">Home</a></li>
<li><a href="forums">Forums</a></li>
<li><a href="?x=servers">Servers</a></li>
<li><a href="?x=matches">Matches</a></li>
<li><a href="?x=about_us">About Us</a></li>
</ul>
</div>[/code]
and this is the php in my page
[code]<?php
if($x=="" ){include"home.php";}
else{include"$x.php";}
?>[/code]
so now when i want to goto the Servers page or the Matches page, it just displays it in the url like this
[code]http://www.kriffer.biz/beta/?x=servers[/code]
so whats the problem?

Share this post


Link to post
Share on other sites
cuz that's what you put in the href in your link tags. try adding [b]index.php[/b]?x=servers etc.. or whatever your main page (home, index, whatever) is.

Share this post


Link to post
Share on other sites
ok that worked. yess. but now take for example this site.... www.mwnx.net click on either downloads or network it doesnt matter. look at the url... it doesnt include like index.php or downloads.php like , now that i just inserted the page it shows up like this sites url with index.php?showtopic=96453

Share this post


Link to post
Share on other sites
please try to explain your question a little more. i don't think i fully understand what you mean.

Share this post


Link to post
Share on other sites
ok goto www.kriffer.biz/beta .... ok the whole point of [code]<?php
if($x=="" ){include"home.php";}
else{include"$x.php";}
?>[/code] this was to keep the banner and footer not change at all.. and only that content the "include' i.e. include"home.php"; change only that data.. so if you clicked on servers or something else on that menu.. it will go and display the data.. right now it just links to the files i just want it to change the inside data the content that says servers. or matches. or about us. or whatever..

Share this post


Link to post
Share on other sites
okay so let's say you have an index.php and it has 3 sections:

example index.php
[code]
<html>
<head></head>
<body>

<!-- header content: let's put your links here, as an example -->
<div>
   <a href = 'index.php?x=home'>home</a> |  
   <a href = 'index.php?x=forum'>forum</a> |
   <a href = 'index.php?x=contact'>contact</a>
</div>

<!-- main content -->
<div>
   <?php
      if ($_GET['x']) {
          include($_GET['x'] . '.php');
      } else {
          include('home.php');
      }
   ?>
</div>

<!-- footer content -->
<div>
   footer stuff here
</div>

</body>
</html>
[/code]
now, this is just a simple example. there are some major security flaws in this. for example, you will at the very least want to create an array of acceptable values of x and only include ($_GET['x'] . '.php'); if $_GET['x'] matches one of the values in the array.

Share this post


Link to post
Share on other sites
ok remember im new to all this.. but ok.. see that php looks different then the php i had in there.. so thats what your suggesting i go with and ok here if this helps any better.. what i was trying to do was create one page with dynamic content

Share this post


Link to post
Share on other sites
well my coding style is slightly different from yours. the point of my example was to look at how it's placed. the only thing i really see [i]wrong[/i] with your actual code is $x is not the same as $_GET['x']; (unless your register globals are on, i think...) but in either case, you need to be using $_GET['x'] not $x, even if it does work.

also, this:

if($x == "")

is not the same as this:

if ($x)

the first one will include your home.php only if someone clicks on a link that has

index.php?x=

notice no value after it. it will not include home.php if they simply typed

index.php in the url, because your condition will only be true if x is set, and equal to "".


Share this post


Link to post
Share on other sites
i see.. well the forums have done me good already... this line you type first time i put it in my code while you were replying and it works.. this line [code] <?php
      if ($_GET['x']) {
          include($_GET['x'] . '.php');
      } else {
          include('home.php');
      }
   ?>[/code] worked.. thxnk alot i'll be back on tommorow

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.