TextFile Updation into php

Discussion in 'PHP' started by jrshelat, Jun 28, 2007.

  1. #1
    Hello to every one

    This is my first forum into php. since i have problem to update the
    text file. i have one form into that form i have teree text box and one button
    in first one Name in second one Password and in third one IP. if button is click
    then i have write the file,append the file and read the file but if i have update into the file then it is not updated. i have update to the existing text file.

    mytext file is

    
    
    [general]
    port=5060
    bindaddr=0.0.0.0
    context=default
    tos=lowdelay
    disallow=all
    ;allow=g729
    allow=ulaw
    
    
    ;register=>wondertech:wondert321@202.78.239.42:5060
    
    [wondertech]
    type=friend
    username=wondertech
    secret=wonder321
    host=202.78.239.42
    canreinvite=no
    fromuser=wondertech
    fromdomain=202.78.239.42
    dtmfmode=rfc2833
    context=default
    disallow=all
    ;allow=ulaw
    allow=g729
    
    
    [1111]
    type=friend
    username=1111
    host=dynamic
    nat=yes                       ; X-Lite is behind a NAT router
    disallow=all
    allow=g729
    allow=ulaw
    canreinvite=no                ; Typically set to NO if behind NAT
    secret=1234
    ;dtmfmode=inband
    dtmf=RFC2833
    
    
    Code (markup):
    i have change to the line of
    ;register=>wondertech:wondert321@202.78.239.42:5060
    after change it
    ;register=>jams:1234xyz@200.76.249.22:5060

    i have not find the position of the file so any one please help me


    my php code is

    
    <?php
    $uname=$_POST['uname'];
    $pass=$_POST['pass'];
    $ip=$_POST['ip'];
    
          $filename = "sip.conf";
    	  $f=fopen($filename,"r");
              
    		  $data=fread($f,filesize($filename));
              fclose($f);  
    		  $delimiter = "\n";
    		  $splitcontents = explode($delimiter, $data);
    		  	  
    		  $f_rep = $splitcontents[10];
    		  $s_rep = $splitcontents[12];
    		  $t_rep = $splitcontents[14];
    		  $four_rep = $splitcontents[15];
    		  $fif_rep = $splitcontents[16];
    		  
    
    	   $str10=";register=>"."$uname".":"."$pass"."@"."$ip".":"."5060";
    	   echo $str10;
    	   $string1=str_replace($f_rep,$str10,$f_rep);
    	   //echo "After Replace $string<br>";
    
    	   $str12="["."$uname"."]";
    	   echo "$str12<br>";
    	   $string2=str_replace($s_rep,$str12,$s_rep);
    
    	   $str14="username="."$uname";
    	   echo "$str14<br>";
    	   $string3=str_replace($t_rep,$str14,$t_rep);
    
    	   $str15="secret="."$pass";
    	   echo "$str15<br>";
    	   $string4=str_replace($four_rep,$str15,$four_rep);
    
    	   $str16="host="."$ip";
    	   echo "$str16<br>";
    	   $string5=str_replace($fif_rep,$str16,$fif_rep);
    	   
    	   foreach( $splitcontents as $record )
            {
    		echo "$record<br>";
            }
    		
    		
     $f1=fopen($filename,"a");
              fwrite($f1,$string1);
    		  fwrite($f1,$string2);
        	  fwrite($f1,$string3);
              fwrite($f1,$string4);
    		  fwrite($f1,$string5);
              fclose($f1);  
        ?>
    
    PHP:
    :confused:
     
    jrshelat, Jun 28, 2007 IP
  2. jrshelat

    jrshelat Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Please help me as soon as possible
     
    jrshelat, Jun 28, 2007 IP
  3. jrshelat

    jrshelat Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Friends,
    I would like to be able to use fwrite to append a string to the Middle of a textfile. The only problem is, the options I have found so far only allow you to replace what is in the text file, or append to the bottom of the text file. Is there not an option to append to the middle of a text file and keep what is already present?
    since i have problem to update the text file. i have one form into that form i have three text box and one buttonin first one Name in second one Password and in third one IP. i have update to the existing text file it very long. i will solve to taken an array.

    mytext file is

    
    
    [general]
    port=5060
    bindaddr=0.0.0.0
    context=default
    tos=lowdelay
    disallow=all
    ;allow=g729
    allow=ulaw
    
    
    ;register=>wondertech:wondert321@202.78.239.42:5060
    
    [wondertech]
    type=friend
    username=wondertech
    secret=wonder321
    host=202.78.239.42
    canreinvite=no
    fromuser=wondertech
    fromdomain=202.78.239.42
    dtmfmode=rfc2833
    context=default
    disallow=all
    ;allow=ulaw
    allow=g729
    
    
    [1111]
    type=friend
    username=1111
    host=dynamic
    nat=yes                       ; X-Lite is behind a NAT router
    disallow=all
    allow=g729
    allow=ulaw
    canreinvite=no                ; Typically set to NO if behind NAT
    secret=1234
    ;dtmfmode=inband
    dtmf=RFC2833
    
    
    Code (markup):
    i have change to the line of
    ;register=>wondertech:wondert321@202.78.239.42:5060
    after change it
    ;register=>jams:1234xyz@200.76.249.22:5060

    i have not find the position of the file so any one please help me


    my php code is

    
    <?php
    $uname=$_POST['uname'];
    $pass=$_POST['pass'];
    $ip=$_POST['ip'];
    
          $filename = "sip.conf";
    	  $f=fopen($filename,"r");
              
    		  $data=fread($f,filesize($filename));
              fclose($f);  
    		  $delimiter = "\n";
    		  $splitcontents = explode($delimiter, $data);
    		  	  
    		  $f_rep = $splitcontents[10];
    		  $s_rep = $splitcontents[12];
    		  $t_rep = $splitcontents[14];
    		  $four_rep = $splitcontents[15];
    		  $fif_rep = $splitcontents[16];
    		  
    
    	   $str10=";register=>"."$uname".":"."$pass"."@"."$ip".":"."5060";
    	   echo $str10;
    	   $string1=str_replace($f_rep,$str10,$f_rep);
    	   //echo "After Replace $string<br>";
    
    	   $str12="["."$uname"."]";
    	   echo "$str12<br>";
    	   $string2=str_replace($s_rep,$str12,$s_rep);
    
    	   $str14="username="."$uname";
    	   echo "$str14<br>";
    	   $string3=str_replace($t_rep,$str14,$t_rep);
    
    	   $str15="secret="."$pass";
    	   echo "$str15<br>";
    	   $string4=str_replace($four_rep,$str15,$four_rep);
    
    	   $str16="host="."$ip";
    	   echo "$str16<br>";
    	   $string5=str_replace($fif_rep,$str16,$fif_rep);
    	   
    	   foreach( $splitcontents as $record )
            {
    		echo "$record<br>";
            }
    		
    		
     $f1=fopen($filename,"a");
              fwrite($f1,$string1);
    		  fwrite($f1,$string2);
        	  fwrite($f1,$string3);
              fwrite($f1,$string4);
    		  fwrite($f1,$string5);
              fclose($f1);  
        ?>
    
    PHP:
    :confused:
     
    jrshelat, Jun 28, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    nico_swd, Jun 28, 2007 IP