8 Replies - 292 Views - Last Post: 01 January 2018 - 12:15 PM Rate Topic: -----

#1 barroncm   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 31-December 17

Issues after first echo

Posted 31 December 2017 - 04:41 PM

I am having an issue with the following php code.
This is being displayed in a web page.

<?
        $ip = "10.10.2.198";
        $port = "80";
        if (! $sock = @fsockopen($ip, $port, $num, $error, 5))
        echo '<img src=/images/red.png height="20" width="20">';
        else{
        echo '<img src=/images/green.png height="20" width="20">';
        fclose($sock);

}

?>



The issue seems to be after the first echo, Im not sure if this is a php issue or not. The code worked prior to updating to php7.

The webpage displays: ';else{ echo '<img src=/images/green.png height="20" width="20">';fclose($sock);

Where it calls for the image it does display the image.

I have been racking my brain and scouring the web but havent found anything that I can see that eludes to a soulution.
I am still fairly a noob with this.
Any direction would be great.
Thanks,
Chris

Is This A Good Question/Topic? 0
  • +

Replies To: Issues after first echo

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5237
  • View blog
  • Posts: 14,031
  • Joined: 18-April 07

Re: Issues after first echo

Posted 31 December 2017 - 05:05 PM

Well I don't think it is because you upgraded to PHP 7. But a few things I want to mention to help clean things up and hopefully solve the problem. First of all, you should always use <?php instead of <?. It is a best practice and doesn't rely on short tags being enabled. Secondly, I try to stay away from single line if statements that don't use curly braces. So try running this and see if it helps...

<?php
        $ip = "10.10.2.198";
        $port = "80";
        if (! $sock = @fsockopen($ip, $port, $num, $error, 5)) {
           echo '<img src=/images/red.png height="20" width="20">';
        } else {
           echo '<img src=/images/green.png height="20" width="20">';
           fclose($sock);

        }

?>


Hope this helps solve the problem. If the problem persists, it might be something else because this code here should work fine. :)

This post has been edited by Martyr2: 31 December 2017 - 05:06 PM

Was This Post Helpful? 0
  • +
  • -

#3 barroncm   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 31-December 17

Re: Issues after first echo

Posted 31 December 2017 - 05:53 PM

View PostMartyr2, on 31 December 2017 - 05:05 PM, said:

Well I don't think it is because you upgraded to PHP 7. But a few things I want to mention to help clean things up and hopefully solve the problem. First of all, you should always use <?php instead of <?. It is a best practice and doesn't rely on short tags being enabled. Secondly, I try to stay away from single line if statements that don't use curly braces. So try running this and see if it helps...

<?php
        $ip = "10.10.2.198";
        $port = "80";
        if (! $sock = @fsockopen($ip, $port, $num, $error, 5)) {
           echo '<img src=/images/red.png height="20" width="20">';
        } else {
           echo '<img src=/images/green.png height="20" width="20">';
           fclose($sock);

        }

?>


Hope this helps solve the problem. If the problem persists, it might be something else because this code here should work fine. :)/>


Thanks Martyr2, unfortunately its still doing the same thing.
cjcomputers.net/testscript.php

here is the entire page code.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CJCOMPUTERS</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<link href='http://fonts.googleapis.com/css?family=Lobster+Two' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Pontano+Sans' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="js/carouselScript.js"></script>
<link href="css/carousel.css" rel="stylesheet" type="text/css">
</head>

<p>Current state of CJCOMPUTERS DHCP </p>

<script language="javascript">
/*Begin Time and Date Script*/


   var dayName = new Array ("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
   var monName = new Array ("January","February","March","April","May","June","July","August","September","October","November","December");
   var now = new Date;
   document.write( dayName[now.getDay()] + ", " + monName[now.getMonth()] + " " + now.getDate())
  </SCRIPT>
<META HTTP-EQUIV="refresh" CONTENT="15">

<table border="0">
<tr>
<td>
Router
</td>
<td>
<?php
        $ip = "10.10.2.198";
        $port = "80";
        if (! $sock = @fsockopen($ip, $port, $num, $error, 5)) {
           echo '<img src=/images/red.png height="20" width="20">';
                   } else {
           echo '<img src=/images/green.png height="20" width="20">';
           fclose($sock);
        }
?>
</td>
</tr>




Any other direction would be great.
Thanks,
Chris
Was This Post Helpful? 0
  • +
  • -

#4 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5237
  • View blog
  • Posts: 14,031
  • Joined: 18-April 07

Re: Issues after first echo

Posted 31 December 2017 - 06:16 PM

Ok well you are doing something bizarre because I can take your page exactly like that and run it just fine. No display of the broken code or anything. How are you testing this code? Btw, where do you define $num and $error? I don't see those in your page.


P.S. Make sure you don't have any weird characters in between your ; and } characters for your else. I don't know what editor you are using, but adding something unusual may cause the php interpreter to see no end of statement semicolon. But that is just a guess.

This post has been edited by Martyr2: 31 December 2017 - 06:20 PM

Was This Post Helpful? 0
  • +
  • -

#5 barroncm   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 31-December 17

Re: Issues after first echo

Posted 31 December 2017 - 07:09 PM

I was wondering if it might be an apache error.
I have another server I can test it on.

I am using notepad++ to do most of the editing. Otherwise I edit straight on the server for small changes.
I will try on my dev server and see what happens.
Thanks for your help.
I will post an update shortly.
Was This Post Helpful? 0
  • +
  • -

#6 barroncm   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 31-December 17

Re: Issues after first echo

Posted 31 December 2017 - 08:38 PM

Looks like there is an issue somewhere else on the server, Im guessing in apache2.
The page works perfect on my dev server.
Thanks for your help Martyr2.
Was This Post Helpful? 0
  • +
  • -

#7 benanamen   User is offline

  • D.I.C Head

Reputation: 24
  • View blog
  • Posts: 169
  • Joined: 28-March 15

Re: Issues after first echo

Posted 01 January 2018 - 10:37 AM

Hopefully you are not using Internet Explorer to test. It is notorious for caching files. It can happen in chrome as well.
Was This Post Helpful? 0
  • +
  • -

#8 barroncm   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 31-December 17

Re: Issues after first echo

Posted 01 January 2018 - 11:56 AM

View Postbenanamen, on 01 January 2018 - 10:37 AM, said:

Hopefully you are not using Internet Explorer to test. It is notorious for caching files. It can happen in chrome as well.


I am using chrome for most testing, but with that being said I also use ctrl+F5 to help solve the cashe issue. I generally dont build sites for IE (I remove it when I can). On a side note the page Im testing has a refresh line in it that I try to add to all my pages while Im developing them.

But I do appreciate the heads up benanamen.
Was This Post Helpful? 0
  • +
  • -

#9 benanamen   User is offline

  • D.I.C Head

Reputation: 24
  • View blog
  • Posts: 169
  • Joined: 28-March 15

Re: Issues after first echo

Posted 01 January 2018 - 12:15 PM

In case you or anyone else doesn't know, Firefox has a Developer Edition of the browser available.
https://www.mozilla....efox/developer/
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1