Setting a variable when clicking link

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Okay I ran into a different problem.

Okay im in index.php?link=2 which is my portfolio section


now I need to get to a link which is index.php?item=2. After I put the 2nd code ( for items ) and I try to load the portfolio section ( link=2) then the page simply keeps on loading itself adding more and more repeated content. I have absolutely no idea how to get around this. Is it not possible to have the same index.php?link= and portfolio.php?link=


sorta confusing......
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Okay nevermind I fixed the logic behind it... but now I ran into yet another problem.

When I click on the second set of links calling up the items=
......grrr so hard to explain......

okay you have index.php?link=2 which calls up portfolio.php

so its index.php?link=2 with the portfolio content displayed. Portfolio also have links calling up portfolio.php=item2 but when I call up that it only brings up the portfolio.php and the new item and not index.php. I understand why it is not working but I do not have the experience to get around this. Help is much appreciated.. .you know I love you guyys
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Sure you can...do this

index.php?link=2&content=1

Just request content and do another if/then statement (case/switch) and it should work.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I've heard about this case/switch stuff... can you refer me to a link so I can learn more about this?
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Case switch is just a if/then statement. But, ok.
http://us4.php.net/manual/en/control-st ... switch.php
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

Unipus wrote:Also, you might make your life a little easier (and the user's, actually) by rewriting it like so:

Code: Select all

$link = $_REQUEST['link']; 
      if($link)
      {
            include($link . ".php");
      } else
      {
            include("main.php");
      }
Example link:
<a href="sections.php?link=portfolio">Portfolio</a>
It's better to use GET, POST or what have you rather than REQUEST.

Be careful about including file names passed via GET: it's very easy to tamper with the query string and so any php file could be included in the above snippet.

Adding a prefix deals with this:

Code: Select all

<?php

      if(isset($_GET['link']))
      {
            include('prefix_' . $_GET['link'] . '.php');
      
      } else {

            include("main.php");
      }

?>
Last edited by McGruff on Tue Aug 09, 2005 11:36 pm, edited 1 time in total.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

much better ty
Post Reply