Hey,

There was a tutorial on this problem I have now but I have lost the link so I am hoping someone here could help :D

Basically, I am looking for the code that you basically use as a replacement for iFrames.

For example, the URL would be www.mysite.com/index.php?page=PAGENAME

and then it opens up in the part of the page in which you enter the code. I'm hoping that makes sense.

Thanks in advance,

Nathan.

Create index.php and put the below code into it.

switch(isset($_REQUEST['page'])){

   case "page1":  
   include("page1.html");
   break;
// this should be your page name e.g, index.php?page=page1

   case "page2":
   include("page2.php");
   break;

   default: // this should be index.php which is default
   include("default.php");
}

Thanks for that, I will try it when I get home.

Another way to do that is

//default index page if your loading all your pages to the index
if(!$_GET['page'] {
include 'home.html'
}

if ($_GET['page'] == page1) {
include 'page1.html';
}

if ($_GET['page'] == page2) {
include 'page2.html';
}

ur page links should be something like this:
index.php?page=page1

The results is the same as the case navigation but just a different method is one better than another not really :P

Hallo,

I have followed the code below to make a small site.

My worry is this. I would like to prevent visitors to access directly my pseudo frames (pages that have been included).

For exemple, I want it a way that if somebody tries to access directly http://www.mysite.com/register.php, the person should automatically re-directed to : http://www.mysite.com/index.php?page=register
where register.php IS NOT PASSWORD PROTECTED !

I have tried meta refresh, it works, but the whote index is refreshing every 1 second, and that's BAD.

Thank you very much, you can contact me directly : webmaster[@]togoenvogue.com

Kamster

Create index.php and put the below code into it.

switch(isset($_REQUEST['page'])){

   case "page1":  
   include("page1.html");
   break;
// this should be your page name e.g, index.php?page=page1

   case "page2":
   include("page2.php");
   break;

   default: // this should be index.php which is default
   include("default.php");
}

Your default case in your switch statement will be fired if none of the other conditions are met. Would that work for you? (I've changed the final include to include register.php from default.php).

switch(isset($_REQUEST['page'])){

case "page1":
include("page1.html");
break;
// this should be your page name e.g, index.php?page=page1

case "page2":
include("page2.php");
break;

default: // this should be index.php which is default
include("register.php");
}

Thanks UnixMonkey for your idea.

I have tried it but doesn't work.

Let me explain more my idea.

The essence is to avoid google or other search engines pointing directly to my included files (register.php, aboutus.php, conditions.php...). Because if somebody clicks on these links, he/she will get a page (with rough text) that comes without template, and I dont want that.
"The person will just close the site, because it's not nice " (Only my index.php is template built)

So I want something like, even if google points www.mysite.com/conditions.php, and the visitor clicks on it, he should be redirected to www.mysite.com/index.php?=conditions
Same for the other pages.

I hope you get me more.

Thanks for your help,

Kamaster


Your default case in your switch statement will be fired if none of the other conditions are met. Would that work for you? (I've changed the final include to include register.php from default.php).

switch(isset($_REQUEST['page'])){

case "page1":
include("page1.html");
break;
// this should be your page name e.g, index.php?page=page1

case "page2":
include("page2.php");
break;

default: // this should be index.php which is default
include("register.php");
}

Okay, how about this, then:

In your index.php file, put a var in there like

$framePage = true;

Then, in your included files 9register.php, aboutus.php, etc) at the top, put this in:

if (!$framePage)
{
  //We'll redirect the user to the proper page
  header("location: index.php?page=".basename($_SERVER['SCRIPT_FILENAME', '.php'));
} else {
  //Page content goes here
}

That will redirect the browser to index.php?page=<whatever page we're at without the .php extension>

Thanks UnixMonkey for your idea.

I have tried it but doesn't work.

Let me explain more my idea.

The essence is to avoid google or other search engines pointing directly to my included files (register.php, aboutus.php, conditions.php...). Because if somebody clicks on these links, he/she will get a page (with rough text) that comes without template, and I dont want that.
"The person will just close the site, because it's not nice " (Only my index.php is template built)

So I want something like, even if google points www.mysite.com/conditions.php, and the visitor clicks on it, he should be redirected to www.mysite.com/index.php?=conditions
Same for the other pages.

I hope you get me more.

Thanks for your help,

Kamaster

Big Thank for this help. I have tried it and it works, at least in local. (easyphp & Mysql). WHen I have uploaded, some pages do not work, I will look at it very well and come back later.

However, I should notice that I have added $framePage to the included pages, other wise, I have an error : Undefined framePage variable

Like this :

$framePage ="" // This is what I have added. Do you think I am wrong ???
if (!$framePage)
{
  //We'll redirect the user to the proper page
  header("location: index.php?page=".basename($_SERVER['SCRIPT_FILENAME'], '.php'));
} else {
  //Page content goes here
}

Thanks once again for your assistance.

Okay, how about this, then:

In your index.php file, put a var in there like

$framePage = true;

Then, in your included files 9register.php, aboutus.php, etc) at the top, put this in:

if (!$framePage)
{
  //We'll redirect the user to the proper page
  header("location: index.php?page=".basename($_SERVER['SCRIPT_FILENAME', '.php'));
} else {
  //Page content goes here
}

That will redirect the browser to index.php?page=<whatever page we're at without the .php extension>

However, I should notice that I have added $framePage to the included pages, other wise, I have an error : Undefined framePage variable

The 'error' you are getting is not an error but a notice. If you have turned on notices in your error_reporting, you will get these kinda notices.

When you include a page into another page, it should take all the variables and use them as it's own.
$framePage ="" will give you the same response every time (try going to one of your pages without your frames page and you should see what I mean.
Are you using classes to encapsulate your pages? It shouldn't make a difference, but try changing your include to a require (same syntax)

Thank you great guys overthere. I will consider all your advices and get back. I will definitively show you my site when ready.

The 'error' you are getting is not an error but a notice. If you have turned on notices in your error_reporting, you will get these kinda notices.

Thank you guys for your help. You may visit http://www.togoenvogue.com to see the result.

But so far, my other worry is this : If you click on any >> button on the homepage, a new window will pop up, because I am using the following code for hit counter :

ONCLICK="javascript:window.open('articles/index.php?page=lire&amp;id_actu=<?php echo $row_LastNews['id_actu']; ?>')"

.

Does anyone know how to make the link open in the SAME window ? (Not in new window).

Thanks once again.

try adding _self to the end of the window.open function. IE:
ONCLICK="javascript:window.open('articles/index.php?page=lire&amp;id_actu=<?php echo $row_LastNews; ?>', _self)"

try adding _self to the end of the window.open function. IE:
ONCLICK="javascript:window.open('articles/index.php?page=lire&amp;id_actu=<?php echo $row_LastNews; ?>', _self)"

I have tried it but didn't work.

The fact is that when onclik opens a new window, the parent is refreshed to incremente the hit counter, and after it is refreshed, it is redirected to the index.php with the following code :

echo "<script language='javascript'>location.href='index.php'</script>";

in the HEADER.

Question : is there any way to put ONCLICK="javascript:window.open('articles/index.php?page=lire&amp;id_actu=<?php echo $row_LastNews; ?>')" under a variable and call that variable in the parent's header ? Something like this :

<header>
echo "<script language='javascript'>location.href='$onclickvariable'</script>"; // ?????????
</header>

Sorry but i am a newbee in php.

In case you need my code source, i will put it here or make it downloadable from my site.

Thanks again.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.