Page 2 of 2

Re: Local server is displaying index.php text

PostPosted: 18. October 2012 10:22
by gary hawkins
Hi Altrea

Sorry I should of pasted that in.

function displayProductSmall($db, $item_list, $img_path, $item_type){
foreach ($item_list as $item_id => $item){

$img_file = $img_path.$item_id.'.jpg';
if (file_exists("$img_file")){
list($width, $height) = getimagesize("$img_file");
$vertical = $height/2;
} else {
$img_file = $img_path.'no_image.jpg';
$width = '45px';
$height = '45px';
$vertical = '23';
}
if ($item_type == 'stack'){
$more_info_link = '?p=stack_details&stack_id='.$item_id;
} else {
$more_info_link = '?p=product_details&prod_id='.$item_id;
}
?>
<div class="sml_prod_box">
<div class="prod_img_small">
<a href="<?php=$more_info_link?>"><img src="<?php=$img_file?>" width="<?php=$width?>" height="<?php=$height?>" style="margin-top: - <?php=$vertical?>px" alt="<?php=$item[0]?>" /></a>
</div>
<a href="<?php=$more_info_link?>"><?php=$item[0]?></a>
</div>



My host for the online website uses Linux. Would I have been better off getting the Linux version of Xampp to run my site locally?

Re: Local server is displaying index.php text

PostPosted: 18. October 2012 16:17
by Altrea
gary hawkins wrote:<a href="<?php=$more_info_link?>"><img src="<?php=$img_file?>" width="<?php=$width?>" height="<?php=$height?>" style="margin-top: - <?php=$vertical?>px" alt="<?php=$item[0]?>" /></a>

Okay, here you are trying to echo variables out.
Before your change it was <?=$variable?>. But the correct replacement for short tags with an echo would be <?php echo $variable ?> and not <?php=$variable?>.
But for short tags with echo you can still use the short tag. It is no longer effected by the short_open_tag setting.

If i were you i would take my favorite plain text editor notepad++, and start a search/replace for the whole directory.
Search for <?php= and replace it with <?= or <?php echo (after that echo there must be a whitespace).

gary hawkins wrote:My host for the online website uses Linux. Would I have been better off getting the Linux version of Xampp to run my site locally?

It is preferable to use a local webserver stack which comes as close as possible to your online servers environment.

Re: Local server is displaying index.php text

PostPosted: 19. October 2012 15:47
by gary hawkins
Hi Altrea,

That worked thankyou! and thank you for suggesting notepad ++!

Now my last problem is undefind varibales. They are everywhere? Here is a sample....

Notice: Undefined variable: level3 in C:\xampp\htdocs\htdocssolo\htdocs\system\mod.functions.inc on line 1053

Notice: Undefined variable: level4 in C:\xampp\htdocs\htdocssolo\htdocs\system\mod.functions.inc on line 1056

Notice: Undefined variable: level5 in C:\xampp\htdocs\htdocssolo\htdocs\system\mod.functions.inc on line 1059

Now as this is every where I guess it is the same sort of thing as last time, one simple change of code should fix the lot. Here is a section of code

} else if (($page == 'stack_admin')||($page == 'edit_registered')||($page == 'order_history')){
$level2 = "<a href=\"$_SESSION[level2_url]\">$_SESSION[level2]</a>";
$level3 = ucfirst(str_replace('_', ' ',$page));
$_SESSION['stack'] = false;
$_SESSION['search'] = false;
} else if ($page == 'payment'){
$level3 = "<a href=\"?p=checkout\">Checkout</a>";
$level4 = ucfirst(str_replace('_', ' ',$page));
}

$breadcrumbs = $level1;
if ($level2 != ''){
$breadcrumbs .=' &gt; '.$level2;
}
if ($level3 != ''){
$breadcrumbs .=' &gt; '.$level3;
}
if ($level4 != ''){
$breadcrumbs .=' &gt; '.$level4;
}
if ($level5 != ''){
$breadcrumbs .=' &gt; '.$level5;
}

return $breadcrumbs;
}

If you could cast your eye over that and oint me in the right direction I would be gratefull

Re: Local server is displaying index.php text

PostPosted: 19. October 2012 17:35
by Altrea
Okay, short lesson in "undefined variable" :D

This message occurs if a variable is not set but you try tu use or output it.

Example:

Code: Select all
} else if (($page == 'stack_admin')||($page == 'edit_registered')||($page == 'order_history')){
    $level2 = "<a href=\"$_SESSION[level2_url]\">$_SESSION[level2]</a>";
    $level3 = ucfirst(str_replace('_', ' ',$page));
    $_SESSION['stack'] = false;
    $_SESSION['search'] = false;
} else if ($page == 'payment'){
    $level3 = "<a href=\"?p=checkout\">Checkout</a>";
    $level4 = ucfirst(str_replace('_', ' ',$page));
}

In your code, $level2 is not set if $page is not equal stack_admin, edit_registered and order_history.

You are using the $level variables to build your breadcrumb navigation:
Code: Select all
$breadcrumbs = $level1;
if ($level2 != ''){
    $breadcrumbs .=' &gt; '.$level2;
}
if ($level3 != ''){
    $breadcrumbs .=' &gt; '.$level3;
}
if ($level4 != ''){
    $breadcrumbs .=' &gt; '.$level4;
}
if ($level5 != ''){
    $breadcrumbs .=' &gt; '.$level5;
}

But an undefined variable is not equal or not equal any value, it is simply undefined.

What you can do to prevent that messages is to modify your code a little bit:
Code: Select all
//instead
[...]
if ($level2 != ''){
    $breadcrumbs .=' &gt; '.$level2;
}
[...]

//do something like this
[...]
if (!empty($level2)){
    $breadcrumbs .=' &gt; '.$level2;
}
[...]

This just works because the !empty() function contains also an isset()

best wishes,
Altrea