Jump to content

Need help with PHP5 code


ghettobsd

Recommended Posts

Hi,

 

I recently upgraded php to work with mysql and something broke! I'm moving a site from a linux host to a bsd host. Everything is working out except for php!

 

The page in question worked fine on linux php5.2.8, and bsd php5-5.2.11. But the difference in version (it happened after i updated mysql) has caused some code to not work properly.

 

The code in question is this:

 

$link_pt1 = '<li';

$link_pt2 = '><a href="';

$link_pt3 = '">';

$link_pt4 = '></a></li>';

 

While on linux host it works great, on bsd it displays:

 

'; $link_pt4 = '>'; $link_01 = home; $link_02 = services; $link_03 = about; $link_04 = contact; $link_05 = espa

 

Everything else is working fine (as far as php is concerned). Any ideas? The only thing I came up with is that > is messing things up. If I remove it everything just ends up being null. If I leave it in I see all that garbage!

 

Thanks!

Link to comment
Share on other sites

I believe that would be : <?php

 

Here is the top part of the file:

 



<?php
function menu(){
echo $name;
global $name;

$active =  " class=\"current_page_item\"";

$link_pt1 = '<li';
$link_pt2 = '><a href="';
$link_pt3 = '">';
$link_pt4 = '</a></li>';

$link_01 = home;
$link_02 = services;
$link_03 = about;
$link_04 = contact;
$link_05 = espanol;
$link_06 = '/forum/';
$link_07 = '/blog/';

$php = ".php";
$esp = "es_pages/index";
$esu = "es_";
$enp = "en_pages/";
$enu = "en_";

$home = Home;
$service = Services;
$about = 'About Us';
$contact = 'Contact';
$espanol ='Español';
$forum = Forum;
$blog = Blog;


if ( $name == "home" ) {
	echo "$link_pt1$active$link_pt2$home$php$link_pt3$home$link_pt4";
	}
else {
	echo "$link_pt1$link_pt2$home$php$link_pt3$home$link_pt4";
	}

if ( $name == services ) {
	echo "$link_pt1$active$link_pt2$enp$enu$link_02$php$link_pt3$service$link_pt4";
	}
else {
	echo "$link_pt1$link_pt2$enp$enu$link_02$php$link_pt3$service$link_pt4";
	}

if ( $name == about ) {
	echo "$link_pt1$active$link_pt2$enp$enu$link_03$php$link_pt3$about$link_pt4";
	}
else {
	echo "$link_pt1$link_pt2$enp$enu$link_03$php$link_pt3$about$link_pt4";
	}

if ( $name == contact ) {
	echo "$link_pt1$active$link_pt2$enp$enu$link_04$php$link_pt3$contact$link_pt4";
	}
else {
	echo "$link_pt1$link_pt2$enp$enu$link_04$php$link_pt3$contact$link_pt4";
	}

echo "$link_pt1$link_pt2$esp$php$link_pt3$espanol$link_pt4";
echo "$link_pt1$link_pt2$link_06$link_pt3$forum$link_pt4";
echo "$link_pt1$link_pt2$link_07$link_pt3$blog$link_pt4";
}
?>
<?php menu();?>	

 

 

thanks!

Link to comment
Share on other sites

Oh, and this is the error I get:

 

[Mon Mar 15 21:42:48 2010] [error] [client ] PHP Notice:  Use of undefined constant home - assumed 'home' in /usr/local/www/apache22/website/index.php on line 3

 

index.php has this:

 

<?php 
$name = home; 
require('header.php'); 
?>

<body>
<!-- start header -->
<!-- end header -->
<!-- start page -->
<div id="page">
<!-- start leftbar -->
<div id="leftbar" class="sidebar">

Link to comment
Share on other sites

When the code is like this: $name = 'home';

i don't get an error but the menu is not displayed.

 

I should explain some more. Every page has the $name = name; code. that way I know where I'm at and the header.php can appropriately highlight the correct section name.

 

so literally, i have : "$name = about;" on my about page, and "$name = home;" in the index.php. This works on the linux host., but not on BSD.

 

thanks!

Link to comment
Share on other sites

no, not constants, just variables.

 

I have 7 tabs. And I want the corresponding tab to be lit up.

 

So that would be:

# Home

# Services

# About Us

# Contact

# Español

# Forum

# Blog

 

and in each "page" they have

"    $name = page-name;    "

If I define a constant, would it still work? because the main page calls the header, and the header processes the name to match it up accordingly.

 

thanks!

Link to comment
Share on other sites

no, not constants, just variables.

 

I have 7 tabs. And I want the corresponding tab to be lit up.

 

So that would be:

# Home

# Services

# About Us

# Contact

# Español

# Forum

# Blog

 

and in each "page" they have

"    $name = page-name;    "

If I define a constant, would it still work? because the main page calls the header, and the header processes the name to match it up accordingly.

 

thanks!

 

You don't need to define constants.  You should be quoting your text.  From what I see, you shouldn't be using globals, either.  You can pass parameters to your "menu" function.

 

I've never used PHP on BSD, but you can try modifying your echoes.  For example:

echo "$link_pt1$link_pt2$enp$enu$link_02$php$link_pt3$service$link_pt4";

to

echo $link_pt1.$link_pt2.$enp.$enu.$link_02.$php.$link_pt3.$service.$link_pt4;

 

You're only concatenating your variables (no literals,) so there's no need for quotes.

Link to comment
Share on other sites

haha yeah, it's not pretty but it works! Well, it works on different php version! What's weird is that it worked fine when I initially installed apahe 2.2 and php5, but once I installed mysql everything went sideways. I've gotten rid of (by correcting) all other messages (whether they ere errors or notices). It's just this that remains.

 

Variables must start with $ so your code is all sorts of broken. Maybe your old server had error reporting turned off but its your code that is the issue.

If you refer to where it shows "# home # services etc" that's now how the code is (it's displayed in a php post earlier). If you refer to something else, how is it f'ed up lol thanks.

 

 

You don't need to define constants.  You should be quoting your text.  From what I see, you shouldn't be using globals, either.  You can pass parameters to your "menu" function.

 

I've never used PHP on BSD, but you can try modifying your echoes.  For example:

echo "$link_pt1$link_pt2$enp$enu$link_02$php$link_pt3$service$link_pt4";

to

echo $link_pt1.$link_pt2.$enp.$enu.$link_02.$php.$link_pt3.$service.$link_pt4;

 

You're only concatenating your variables (no literals,) so there's no need for quotes.

 

Ok I'll try that out and report how it works out. Thanks for the help ma!

Link to comment
Share on other sites

OK, so I started going through the code to make the changes and I added 's to $name = 'page';

Then I decided to go from bottom up. That's when I saw this:

 

<? menu();?>

 

And would you believe that once i changed that to:

<?php menu(); ?>	

made all the difference in the world? haha So now it's working again. Apparently the previous version didn't complain about not having ?php yet it worked.

 

So I fixed it in both english and spanish versions and they both work!

 

Thanks for all your help guys!

 

 

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.