Jump to content

[SOLVED] PHP working in 4.4.8 but not 5.2.5


jsciarrino

Recommended Posts

A client moved his host acct. New host runs php 5.2.5, old host was 4.4.8. The following code worked on the old host but not on the new one. I'm a php novice, really trenched down and figured this out when I first worked with the client to get this working but am in a pinch here to get them back up asap. Trying to figure this out, hope someone could help. For all I know it could be a simple fix, hope so :) Thanks in advance for any help/explanation. I don't want to just have somebody debug for me, if somebody sees the problem and could take the time to explain I would appreciate that even more.

 

<?php $page_title="attorney"; include('header.php'); ?>

<? 
if ( $bio == "attorney 1 name" ) { 
$MyArray = array( "Attorney 1", "email: <a href=\"mailto:attorney1@attorney.com\">attorney1@attorney.com</a>","Attorney 1 description, hooray.");

} else if ( $bio == "attorney 2 name" ) { 
$MyArray = array( "Attorney 2", "email: <a href=\"mailto:attorney2@attorney.com\">attorney2@attorney.com</a>","Attorney 2 description, hooray.");

}
?>


	<h2 id="title"><?echo $MyArray[0]?></h2>

	<p class="cinfo"><?echo $MyArray[1]?></p>
	<p class="cinfo">
	phone: 1234567<br>
	fax: 1234567
	</p>


	<p><?echo $MyArray[2]?> </p>

<? include("footer.php") ?>

Link to comment
Share on other sites

Would help if you explained what doesn't actually work.

 

One thing that happens on a update is the php.ini file is set to default.  Are short tags enabled?  If not, change your <? to <?PHP

 

If this is all your code, where do you set your variables?  $bio isn't defined.

 

 

Link to comment
Share on other sites

Short tags could be disabled (if that is possible)

 

<?php
if ( $bio == "attorney 1 name" ) {
   $MyArray = array( "Attorney 1", "email: <a href=\"mailto:attorney1@attorney.com\">attorney1@attorney.com</a>","Attorney 1 description, hooray.");

} else if ( $bio == "attorney 2 name" ) {
   $MyArray = array( "Attorney 2", "email: <a href=\"mailto:attorney2@attorney.com\">attorney2@attorney.com</a>","Attorney 2 description, hooray.");

}
?>


      <h2 id="title"><?php echo $MyArray[0];?></h2>
      
      <p class="cinfo"><?php echo $MyArray[1];?></p>
      <p class="cinfo">
      phone: 1234567<br>
      fax: 1234567
      </p>

      
      <p><?php echo $MyArray[2];?> </p>

<?php include("footer.php"); ?>

 

Also where is BIO set? If it is from GET or POST you need to access with $_GET, $_POST. Since PHP 5 has register_globals turned off by default for security reasons.

 

Edit:

Fixed assuming $bio is coming from a form

<?php
$bio = isset($_REQUEST['bio'])?$_REQUEST['bio']:null;

if ( $bio == "attorney 1 name" ) {
   $MyArray = array( "Attorney 1", "email: <a href=\"mailto:attorney1@attorney.com\">attorney1@attorney.com</a>","Attorney 1 description, hooray.");

} else if ( $bio == "attorney 2 name" ) {
   $MyArray = array( "Attorney 2", "email: <a href=\"mailto:attorney2@attorney.com\">attorney2@attorney.com</a>","Attorney 2 description, hooray.");

}
?>


      <h2 id="title"><?php echo $MyArray[0];?></h2>
      
      <p class="cinfo"><?php echo $MyArray[1];?></p>
      <p class="cinfo">
      phone: 1234567<br>
      fax: 1234567
      </p>

      
      <p><?php echo $MyArray[2];?> </p>

<?php include("footer.php"); ?>

Link to comment
Share on other sites

Would help if you explained what doesn't actually work.

 

One thing that happens on a update is the php.ini file is set to default.  Are short tags enabled?  If not, change your <? to <?PHP

 

If this is all your code, where do you set your variables?  $bio isn't defined.

 

What is not working is the part where the MyArrays should display, they display nothing.

Bio is defined in the links to this page, ie, <a href=attorney_bio.php?bio=Attorney1>

Link to comment
Share on other sites

Would help if you explained what doesn't actually work.

 

One thing that happens on a update is the php.ini file is set to default.  Are short tags enabled?  If not, change your <? to <?PHP

 

If this is all your code, where do you set your variables?  $bio isn't defined.

 

What is not working is the part where the MyArrays should display, they display nothing.

Bio is defined in the links to this page, ie, <a href=attorney_bio.php?bio=Attorney1>

 

So you need to access it with $_GET, since register_globals is off. Also check the if statement, it should be == "Attorney1"

 

?php
$bio = isset($_GET['bio'])?$_GET['bio']:null;

if ( $bio == "Attorney1" ) {
   $MyArray = array( "Attorney 1", "email: <a href=\"mailto:attorney1@attorney.com\">attorney1@attorney.com</a>","Attorney 1 description, hooray.");

} else if ( $bio == "Attorney2" ) {
   $MyArray = array( "Attorney 2", "email: <a href=\"mailto:attorney2@attorney.com\">attorney2@attorney.com</a>","Attorney 2 description, hooray.");

}
?>


      <h2 id="title"><?php echo $MyArray[0];?></h2>
     
      <p class="cinfo"><?php echo $MyArray[1];?></p>
      <p class="cinfo">
      phone: 1234567<br>
      fax: 1234567
      </p>

     
      <p><?php echo $MyArray[2];?> </p>

<?php include("footer.php"); ?>

 

Give that a try and see if it works.

 

I would read up on register_globals so you can fix the rest of the code that assumes it is on.

Link to comment
Share on other sites

Would help if you explained what doesn't actually work.

 

One thing that happens on a update is the php.ini file is set to default.  Are short tags enabled?  If not, change your <? to <?PHP

 

If this is all your code, where do you set your variables?  $bio isn't defined.

 

What is not working is the part where the MyArrays should display, they display nothing.

Bio is defined in the links to this page, ie, <a href=attorney_bio.php?bio=Attorney1>

 

So you need to access it with $_GET, since register_globals is off. Also check the if statement, it should be == "Attorney1"

 

?php
$bio = isset($_GET['bio'])?$_GET['bio']:null;

if ( $bio == "Attorney1" ) {
   $MyArray = array( "Attorney 1", "email: <a href=\"mailto:attorney1@attorney.com\">attorney1@attorney.com</a>","Attorney 1 description, hooray.");

} else if ( $bio == "Attorney2" ) {
   $MyArray = array( "Attorney 2", "email: <a href=\"mailto:attorney2@attorney.com\">attorney2@attorney.com</a>","Attorney 2 description, hooray.");

}
?>


      <h2 id="title"><?php echo $MyArray[0];?></h2>
     
      <p class="cinfo"><?php echo $MyArray[1];?></p>
      <p class="cinfo">
      phone: 1234567<br>
      fax: 1234567
      </p>

     
      <p><?php echo $MyArray[2];?> </p>

<?php include("footer.php"); ?>

 

Give that a try and see if it works.

 

I would read up on register_globals so you can fix the rest of the code that assumes it is on.

 

This worked! Why would this have worked before without declaring $bio?

 

Thank you so much to all for replying, and so quickly! I'll certainly be spending more time here in the future. There is another part not working right now but I'm going to give that a try before asking for more help. Thanks again.

Link to comment
Share on other sites

This worked! Why would this have worked before without declaring $bio?

 

Thank you so much to all for replying, and so quickly! I'll certainly be spending more time here in the future. There is another part not working right now but I'm going to give that a try before asking for more help. Thanks again.

 

Umm did you read my reply?

 

Register_globals is a security risk. In PHP5 it is defaulted to off. What register_globals would do is take global variables, such as $_GET and $_POST and convert the arrays to actual variables. So $_GET['bio'] was the same as $bio. But this could cause major issues. So because of that they decided to make the user define the variable to prevent a security breach, thus you now have to set variables, which is the way it should be or access them manually via the array of $_GET/$_POST.

 

Read up on register_globals if you want more explanation, as I stated in the past 2 posts.

Link to comment
Share on other sites

Got it, thanks. The other problem I was having that I mentioned was along the exact same lines. I'm finished with this site now thanks to the help here and on to another project that I'm hoping to make all php with a mysql dbase. That should be a pretty good learning experience for me, will definitely be around here with some questions then. Thanks again guys (and gals?), you helped keep a few more dark hairs on my head ;D

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.