Jump to content

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?
Link to comment
https://forums.phpfreaks.com/topic/12612-help/
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
Link to comment
https://forums.phpfreaks.com/topic/12612-help/#findComment-48364
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..
Link to comment
https://forums.phpfreaks.com/topic/12612-help/#findComment-48376
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.
Link to comment
https://forums.phpfreaks.com/topic/12612-help/#findComment-48378
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 "".


Link to comment
https://forums.phpfreaks.com/topic/12612-help/#findComment-48380
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
Link to comment
https://forums.phpfreaks.com/topic/12612-help/#findComment-48382
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.