Jump to content

Rather stuck using "include $_GET..."


Recommended Posts


I am having some real problems with the code in red below which sits in my "index.php" file, and would be very grateful for any help!




include $_GET["view"] . ".php";




The links for my "views" (e.g. <a href="?view=page_news">News</a> ) are in my "header.php" file.


The whole website works absolutely fine, except when you first arrive on the homepage you get:

Notice: Undefined index: view

Warning: include(.php) [function.include]: failed to open stream: No such file or directory

This is presumably because a link hasn't been clicked yet, thus a "view" hasn't been defined yet, but I have no idea how to get around this!


I hope I haven't been too vague with my explanation...





Link to comment
Share on other sites

if (isset($_GET['view'])) {
  include $_GET["view"] . ".php"; 
} else {
  // include some default


you'd best check the file exists locally before including it too as this method alone opens a massive security hole.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

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

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.