Jump to content

*SOLVED* variable problem


salvador2001

Recommended Posts

hi all,

I am very noob with PHP and i cant get this script working right.
Now i got a variable error on the section "load in directory"

Can anyone please adjust this script for me ?

<?php

// load existing pages

if(isset($_GET['load'])) {
switch($_GET['load']) {
case 'news':
case 'about':
case 'members':
$load = $_GET['load'];
break;
default:
$load = 'welcome';
}
}

// load in root directory

if (is_file($load . ".php")) {
include($load . ".php");
}

// load errorpage

else {
include("error404.php");
}

?>
Link to comment
Share on other sites

The problem is that if $_GET['load'] isn't set, then the variable $load isn't defined. Do this before your switch to make sure that $load is always defined:
[code]<?php if (!isset($_GET['load'])) $load = 'welcome'; ?>[/code] or something similar.

Ken
Link to comment
Share on other sites

Thanks a lot !, the error message is gone.
But now there is one thing left, it keeps loading the errorpage at start while it should display the welcome page. Its a dynamic page so he doesnt load the content it should.
any idea what is going wrong ?

This is the script so far;

<?php

// only this pages are allowed

if(isset($_GET['load'])) {
switch($_GET['load']) {
case 'news':
case 'about':
case 'members':
$load = $_GET['load'];
break;
default:
$load = 'welcome';
}
}

// load files in rootdirectory

if (!empty($load)) {
if (is_file($load . ".php")) {
include($load . ".php");
}
}

// loading error page

else {
include("error404.php");
}

?>
Link to comment
Share on other sites

If you had implemented my suggestion instead of the one from [b]Yesideez[/b] you it would be working.

Here is my suggestion again:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Do this before your switch to make sure that $load is always defined:
[code]<?php if (!isset($_GET['load'])) $load = 'welcome'; ?>[/code][/quote]

Ken
Link to comment
Share on other sites

Thanks, someone got it solved for me and its working. For other people this could be a good example so i post the working script here.

[code]<?php  

// only this pages are allowed

if(isset($_GET['load'])) {  
  switch($_GET['load']) {  
    case 'news':  
    case 'about':  
    case 'members':  
      $load = $_GET['load'];  
      break;  
    default:  
      $load = 'welcome';  
  }
} else {
  $load = 'welcome';    // -- if $_GET['load'] is not defined
}  

// load files in rootdirectory

if (is_file($load . ".php")) {  
include($load . ".php");  
}  

// loading errorpage

else {  
include("error404.php");  
}  

?>
[/code]
Link to comment
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.