Easy A
Would you like to react to this message? Create an account in a few clicks or log in to continue.


 
HomeHome  Latest imagesLatest images  SearchSearch  RegisterRegister  Log inLog in  

Share
 

 Change IP Address in PHP

View previous topic View next topic Go down 
AuthorMessage
Plobo
Member
Member
Plobo

Posts : 3
Join date : 2011-07-11

Change IP Address in PHP Empty
PostSubject: Change IP Address in PHP   Change IP Address in PHP EmptyThu Jul 14, 2011 12:32 am

I am developing a system in PHP wherein I can change the IP Address and Subnet in web form.

I need assistance here becoz I cannot solve this problem.

Here's a code:
Code:

<?php

echo "Old IP: ".$old_ip;
echo "New IP: ".$stat_ip;

system("sed -i 's|".$old_ip."|".$stat_ip."|g' /etc/.../.../ifcfg-eth0");

?>


the error is "unterminated 's' command"... what is the right syntax for here?

thanks~
Back to top Go down
CaptainCop
Member
Member
avatar

Posts : 14
Join date : 2011-03-09

Change IP Address in PHP Empty
PostSubject: Re: Change IP Address in PHP   Change IP Address in PHP EmptyThu Jul 14, 2011 12:33 am

For a start do away with all those double quotes you're using. Check out the link in my signature about quotes to see how to tidy that up.
Back to top Go down
Skilletrockz
Super Moderator
Super Moderator
Skilletrockz

Posts : 45
Join date : 2011-05-11

Change IP Address in PHP Empty
PostSubject: Re: Change IP Address in PHP   Change IP Address in PHP EmptyThu Jul 14, 2011 12:34 am

You're using pipes instead of a forwardslash:
Code:

system('sed -i \'s/' . $old_ip . '/' . $stat_ip . '/g\' /etc/ifcfg-eth0'); // sed expects: sed -i 's/oldText/newText/g' /path/to/file 

I hope you are taking precautions to prevent people from being able to execute this remotely. It wouldn't be very difficult to render your box inaccessible remotely or worse.
Back to top Go down
Plobo
Member
Member
Plobo

Posts : 3
Join date : 2011-07-11

Change IP Address in PHP Empty
PostSubject: Re: Change IP Address in PHP   Change IP Address in PHP EmptyThu Jul 14, 2011 12:35 am

thanks for the reply...i'll check on these..
Back to top Go down
Kinkii
Member
Member
avatar

Posts : 13
Join date : 2011-03-09

Change IP Address in PHP Empty
PostSubject: Re: Change IP Address in PHP   Change IP Address in PHP EmptyThu Jul 14, 2011 12:36 am

My linux is rusty at best, but I thought the pattern re-placer would allow pipebars as delimiters?
The error itself is definitely not a PHP error though, so its the usage of SED that's causing that. I'll move this to the computer programming forum instead.
Back to top Go down
Sponsored content




Change IP Address in PHP Empty
PostSubject: Re: Change IP Address in PHP   Change IP Address in PHP Empty

Back to top Go down
 

Change IP Address in PHP

View previous topic View next topic Back to top 
Page 1 of 1

 Similar topics

-
» Change reputation name
» Change the sk currency name
» Reputation name change =>Fame
» Need to change my Name on Facebook ...I'm very irritated
» i want to change domain name that i order

Permissions in this forum:You cannot reply to topics in this forum
Easy A :: Change IP Address in PHP Edit-trash Useless :: Trash-