azpyroguy Posted June 24, 2010 Share Posted June 24, 2010 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] Quote Link to comment Share on other sites More sharing options...
Jax2 Posted June 25, 2010 Share Posted June 25, 2010 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> Quote Link to comment Share on other sites More sharing options...
azpyroguy Posted June 25, 2010 Author Share Posted June 25, 2010 It's possible... but when I implement any portion of the if and else code, I get a complete blank page... so I think something is wrong in the way I am doing this... as when I remove the if else code, I get my page back... Quote Link to comment Share on other sites More sharing options...
closerwalk Posted June 25, 2010 Share Posted June 25, 2010 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> Quote Link to comment Share on other sites More sharing options...
Jax2 Posted June 25, 2010 Share Posted June 25, 2010 I was trying to correct it in my code paste as well, but it didn't look as nice as yours Quote Link to comment Share on other sites More sharing options...
closerwalk Posted June 25, 2010 Share Posted June 25, 2010 I was trying to correct it in my code paste as well, but it didn't look as nice as yours 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, Quote Link to comment Share on other sites More sharing options...
closerwalk Posted June 25, 2010 Share Posted June 25, 2010 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... Quote Link to comment Share on other sites More sharing options...
azpyroguy Posted June 25, 2010 Author Share Posted June 25, 2010 Thanks. I will try it when I get back to the office on Monday and have access to the server. Quote Link to comment Share on other sites More sharing options...
closerwalk Posted June 28, 2010 Share Posted June 28, 2010 sorry something else I noticed: REMOTE_ADDR should be $_SERVER['REMOTE_ADDR']; Quote Link to comment Share on other sites More sharing options...
azpyroguy Posted June 28, 2010 Author Share Posted June 28, 2010 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">'; } Quote Link to comment Share on other sites More sharing options...
closerwalk Posted June 28, 2010 Share Posted June 28, 2010 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] Quote Link to comment Share on other sites More sharing options...
closerwalk Posted June 28, 2010 Share Posted June 28, 2010 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. Quote Link to comment Share on other sites More sharing options...
closerwalk Posted June 28, 2010 Share Posted June 28, 2010 Just checking: Did you try out my changes? Quote Link to comment Share on other sites More sharing options...
azpyroguy Posted June 29, 2010 Author Share Posted June 29, 2010 Just checking: Did you try out my changes? I will try them out on Tuesday when I get back to the office... I left the office at 4:00pm today and did not see your reply. Quote Link to comment Share on other sites More sharing options...
azpyroguy Posted June 29, 2010 Author Share Posted June 29, 2010 Thank-you, this code is working now. =) Quote Link to comment Share on other sites More sharing options...
closerwalk Posted June 29, 2010 Share Posted June 29, 2010 Pleae mark as solved. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.