Jump to content

Recommended Posts

Hello!

 

I am new to this forum, and I tried to search for my question

but I didn't find anything so I decided to ask:

 

EDIT: I did a few more searches and now I found some potential

examples. I would still like your help though!

 

I have three sites:

 

index.php <- main site

links.php <- site with 5 different links

home.php <- site with contents for home

portfolio.php <- site with contents for portfolio

 

Question:

When you first start index.php, links.php and home.php are included. I wonder how would I, in PHP, be able to include the correct site, for the content for each link that has been pressed?

 

Example:

 

Index.php -

Link 1, Link 2, ink 3, ink 4, ink 5,

Home content( Welcome to my site etc..!)

 

Press Link 1 and reload index.php with the links.php included as well as portfolio.php (or some other site).

Press Link 2 and reload index.php with the links.php included as well as guestbook.php (or some other site).

 

###########

 

I could use an iframe instead, but I wish to learn how to do this in PHP.

Please, help me!

 

Cheers,

Zolomon

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/84607-solved-php-include/
Share on other sites

Hello!

 

Thank you for your help, very appreciated.

 

This is what I have tried so far, without success:

 

On index.php:

<?php

  $link = isset($_GET['link']) ? $_GET[['link'] : 'home';  

  include("{$link}.php");

?>

 

and then this on links.php:

<?php

echo '<a href="index.php?link=home"><span>Home</span></a>';

echo '<a href="index.php?link=links"><span>Links</span></a>';

echo '<a href="index.php?link=about"><span>About</span></a>';

echo    '<a href="index.php?link=guestbook"><span>Guestbook</span></a>';

echo '<a href="index.php?link=portfolio"><span>Portfolio</span></a>';

echo '<a href="index.html?link=link4" id="last"><span>Link 4</span></a>';

?>

 

but it does not seem to work. I tried to use your if/else statement but that did not work either.

 

Cheers,

Zolomon

Link to comment
https://forums.phpfreaks.com/topic/84607-solved-php-include/#findComment-431159
Share on other sites

Managed to solve it with:

index.php

<?php

$pages = array('home', 'links', 'about', 'guestbook', 'portfolio', 'link4');

 

if (isset($_REQUEST['link']) && in_array($_REQUEST['link'], $pages))

{

$include = $_REQUEST['link'];

} else {

$include = 'home';

}

include('content/'.$include .'.php');

?>

Link to comment
https://forums.phpfreaks.com/topic/84607-solved-php-include/#findComment-431228
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.