Jump to content

Variables, ifs, else ifs, with echos.


azpyroguy

Recommended Posts

This is a landing page that gets displayed when a user connects to our VPN server (page is hosted on a Ubuntu 10.4 server)

 

The idea behind this is having this script which is embedded inside of a HTML document (that part works), and do get the "YOUR IP ADDRESS IS" to work without the "ifs and else". 

 

The function of this script is simple, set a variable of the users currently assigned IP by the VPN, then check based on that variable, if they are assigned a 10.65.x.x IP they get a "CONNECTED" echoed in the box, and if any other IP is found, or not found the receive a "FAILED" message in the box, and then a pop up html message that provides them information about why their connection has failed.

 

I am having some trouble getting this to run properly.. I get no errors, from I can see, but no page display either...

 

<?$VPNremote_ip = "REMOTE_ADDR"; ?>

        <div class="lowerMessage" style="MARGIN: 10px auto; WIDTH: 400px">

<p align="left">

        <? if (VPNremote_ip == "10.65") echo SSL CONNECTION STATUS - <span style="COLOR: #000099; FONT-SIZE: 14px; FONT-WEIGHT: bold">CONNECTED</span> </p>

<p align="left">;

        else if echo SSL CONNECTION STATUS - <span style="COLOR: #cc0000; FONT-SIZE: 14px; FONT-WEIGHT: bold">FAILED</span>

 

                        <script type="text/javascript">

                                openWin('not_connected.html');

                        </script>

?>

                <br ><br >

                YOUR IP ADDRESS IS: <b><? echo getenv('REMOTE_ADDR'); ?></b></p>

 

 

Anyone got any ideas on what I am doing wrong here...

 

I have attached a screen grab, showing on the script is working.. sort of...

 

[attachment deleted by admin]

Link to comment
Share on other sites

May not be correct, but from what I see in the code, it looks like you're saying if their IP address is EXACTLY 10.65, then show them connected ...

 

Wouldn't it need to be if ($remote_addr like 10.65%) { ...etc ?

 

<?php

$VPNremote_ip = "REMOTE_ADDR"; 

?>
        <div class="lowerMessage" style="MARGIN: 10px auto; WIDTH: 400px">
<p align="left">

<?php

if (VPNremote_ip == "10.65") 
{

?>
SSL CONNECTION STATUS- <span style="COLOR: #000099; FONT-SIZE: 14px; FONT-WEIGHT: bold">CONNECTED</span> </p>
<p align="left">

<?php
}
else 
{
?>

SSL CONNECTION STATUS - <span style="COLOR: #cc0000; FONT-SIZE: 14px; FONT-WEIGHT: bold">FAILED</span>

<?php
}
                        <script type="text/javascript">
                                openWin('not_connected.html');
                        </script>
                <br ><br >
                YOUR IP ADDRESS IS: <b><?php echo getenv('REMOTE_ADDR'); ?></b></p>

Link to comment
Share on other sites

A few things wrong with your code.  Blank page most of the time if not always indicates that you have errors in your PHP coding.  You need to turn on error checking your scripts when you write them.  Also you should use logical scripting so that people can read your code and help you. 

<?PHP

 

IF CONDITIONS {

  DO SOMETHING HERE

}

ELSE  {

  DO THIS

 

}

 

?>

On your if statement which I didn't change to what I am going to suggest but.  If you want that portion to work I would use string positive:

 

E.G.

 

<?php
$mystring = "REMOTE_ADDR";
$findme   = '10.65.';
$pos = strpos($, $findme);

// Note our use of ===.  Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
    echo "The string '$findme' was not found in the string '$mystring'";
} else {
    echo "The string '$findme' was found in the string '$mystring'";
    echo " and exists at position $pos";
}
?> 

 

It should always be like:

 

 

<?php

$VPNremote_ip = "REMOTE_ADDR"; 

?>


		<div class="lowerMessage" style="MARGIN: 10px auto; WIDTH: 400px">
		<p align="left">
<?php 

if (VPNremote_ip == "10.65") {
   echo 'SSL CONNECTION STATUS - <span style="COLOR: #000099; FONT-SIZE: 14px; FONT-WEIGHT: bold">CONNECTED</span> </p><p>align="left">';
}

else { 
   echo 'SSL CONNECTION STATUS - <span style="COLOR: #cc0000; FONT-SIZE: 14px; FONT-WEIGHT: bold">FAILED</span>';
}
?>
		<script type="text/javascript">';
		openWin('not_connected.html');
		</script>

                	<br ><br >
                	YOUR IP ADDRESS IS: <b><? echo getenv('REMOTE_ADDR'); ?></b></p>

Link to comment
Share on other sites

I was trying to correct it in my code paste as well, but it didn't look as nice as yours :D

 

 

Oh no worries.  I was just letting you know that it makes it easier if you write it both for others and for your self.  Hard to see the problem and unless you follow logically. 

 

 

PS. You were missing  "" and other things that prevented your code from running.  Look up turning on error reporting scripts it helps.  Like missing T_STRING would point you to say a missing ' or " or ; and the line that its having issues with.  Always good practice when having issues to turn on error reporting.

 

Thanks,

Link to comment
Share on other sites

A few things wrong with your code.  Blank page most of the time if not always indicates that you have errors in your PHP coding.  You need to turn on error checking your scripts when you write them.  Also you should use logical scripting so that people can read your code and help you. 

<?PHP

 

IF CONDITIONS {

  DO SOMETHING HERE

}

ELSE  {

  DO THIS

 

}

 

?>

On your if statement which I didn't change to what I am going to suggest but.  If you want that portion to work I would use string positive:

 

E.G.

 

<?php
$mystring = "REMOTE_ADDR";
$findme   = '10.65.';
$pos = strpos($mystring , $findme);

// Note our use of ===.  Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
    echo "The string '$findme' was not found in the string '$mystring'";
} else {
    echo "The string '$findme' was found in the string '$mystring'";
    echo " and exists at position $pos";
}
?> 

 

It should always be like:

 

 

<?php

$VPNremote_ip = "REMOTE_ADDR"; 

?>


		<div class="lowerMessage" style="MARGIN: 10px auto; WIDTH: 400px">
		<p align="left">
<?php 

if (VPNremote_ip == "10.65") {
   echo 'SSL CONNECTION STATUS - <span style="COLOR: #000099; FONT-SIZE: 14px; FONT-WEIGHT: bold">CONNECTED</span> </p><p>align="left">';
}

else { 
   echo 'SSL CONNECTION STATUS - <span style="COLOR: #cc0000; FONT-SIZE: 14px; FONT-WEIGHT: bold">FAILED</span>';
}
?>
		<script type="text/javascript">';
		openWin('not_connected.html');
		</script>

                	<br ><br >
                	YOUR IP ADDRESS IS: <b><? echo getenv('REMOTE_ADDR'); ?></b></p>

 

Let me know if you get it working... :)

Link to comment
Share on other sites

I think its close...

 

I am now getting the echo of the failed message properly.

 

I even tried to place these to try and get the success message to appear... so it acts like its not receiving the proper variable

 

$VPNremote_ip = $_SERVER['REMOTE_ADDR'];

 

if (VPNremote_ip == "10.12%") {

  echo 'SSL CONNECTION STATUS - <span style="COLOR: #000099; FONT-SIZE: 14px; FONT-WEIGHT: bold">CONNECTED</span> </p><p>align="left">';

}

 

or

$VPNremote_ip = $_SERVER['REMOTE_ADDR'];

 

if (VPNremote_ip == "my.ip.address.here") {

  echo 'SSL CONNECTION STATUS - <span style="COLOR: #000099; FONT-SIZE: 14px; FONT-WEIGHT: bold">CONNECTED</span> </p><p>align="left">';

}

 

 

 

 

Link to comment
Share on other sites

 

Tried this and it works.  Another best practice is to echo out dependent varibles like:

echo 'VPN REMOTE IP ADDRESS IS:' .$VPNremote_ip . '</br>';  //check to see if the $_SERVER['REMOTE_ADDR'] is pulling an ip

 

<?php

$VPNremote_ip = $_SERVER['REMOTE_ADDR'];
echo 'VPN REMOTE IP ADDRESS IS:' .$VPNremote_ip . '</br>';  //check to see if the $_SERVER['REMOTE_ADDR'] is pulling an ip

$validip = '10.0'; //This is a valid ip range
$pos = strpos($VPNremote_ip, $validip);

if ($pos !== false) {
   echo 'SSL CONNECTION STATUS - <span style="COLOR: #000099; FONT-SIZE: 14px; FONT-WEIGHT: bold" align="left">CONNECTED</span></p><p>';
}else {
echo 'SSL CONNECTION STATUS - <span style="COLOR: RED; FONT-SIZE: 14px; FONT-WEIGHT: bold" align="left">NOT CONNECTED</span></p><p>';
}


?>

[img][/img]

Link to comment
Share on other sites

I think its close...

 

I am now getting the echo of the failed message properly.

 

I even tried to place these to try and get the success message to appear... so it acts like its not receiving the proper variable

 

$VPNremote_ip = $_SERVER['REMOTE_ADDR'];

 

if (VPNremote_ip == "10.12%") {

  echo 'SSL CONNECTION STATUS - <span style="COLOR: #000099; FONT-SIZE: 14px; FONT-WEIGHT: bold">CONNECTED</span> </p><p>align="left">';

}

 

or

$VPNremote_ip = $_SERVER['REMOTE_ADDR'];

 

if (VPNremote_ip == "my.ip.address.here") {

  echo 'SSL CONNECTION STATUS - <span style="COLOR: #000099; FONT-SIZE: 14px; FONT-WEIGHT: bold">CONNECTED</span> </p><p>align="left">';

}

 

I noticed you are forgetting to place $ in front of your varibles in your if statements too.

 

 

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.