Current location: Hot Scripts Forums » Programming Languages » PHP » How to edit a .php file in php


How to edit a .php file in php

Reply
  #1 (permalink)  
Old 06-20-11, 04:05 AM
Mr_Matijs Mr_Matijs is offline
New Member
 
Join Date: Jun 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
How to edit a .php file in php

Hi,

I want this file:

PHP Code:

<?php  


$session_username 
$_SESSION['username'];
$userdb "".$session_username."_";

if(!
$session_username){
 echo 
"Youre not logged in";
}else{
 
$result mysql_query("UPDATE ".$session_username."users SET name='test' WHERE id='1'");
}

?>
To be in another file ... But this needs to happens in a .php file !!!

Can somebody help me ?

Thanks,

Matijs
Reply With Quote
  #2 (permalink)  
Old 06-20-11, 06:30 AM
jamhassan jamhassan is offline
New Member
 
Join Date: Jun 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Sorry but you can visit w3school provide you complete information about php coding lots of the engineer visit daily this site then get extra technique relevant of his subject because that is the important sites who provide you complete information of web development.
Reply With Quote
  #3 (permalink)  
Old 06-20-11, 07:50 AM
Niall's Avatar
Niall Niall is offline
Newbie Coder
 
Join Date: Feb 2011
Location: Kernow
Posts: 85
Thanks: 10
Thanked 3 Times in 3 Posts
Do you mean you want to have two files - One that contains that script and another file that calls the file with the script in it?
That's fairly simple to do:
PHP Code:

<?php include "script.php"?>

Or another way of doing it is:
PHP Code:

<?php require "script.php"?>

The difference is that if you 'include' a file that doesn't exist, the script should ignore it. If you 'require' it then the script will produce an error message.

It looks like you're trying to use a login system. I would recommend using 'require' instead of include because this will reduce the possibility of security problems.

I hope that helps!
Reply With Quote
  #4 (permalink)  
Old 06-20-11, 12:54 PM
Mr_Matijs Mr_Matijs is offline
New Member
 
Join Date: Jun 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
thanks,

but it needs to sent into a directory with a code
matijs
Reply With Quote
  #5 (permalink)  
Old 06-20-11, 04:07 PM
Niall's Avatar
Niall Niall is offline
Newbie Coder
 
Join Date: Feb 2011
Location: Kernow
Posts: 85
Thanks: 10
Thanked 3 Times in 3 Posts
Oh, you mean it needs to make a new file?
That would be something like:
PHP Code:

<?php

$filename 
"file.php"// This is what you want to save the file as.
$content "content goes here"// This is the stuff that you want to put into the file.

file_put_contents($filename$content);
?>
I haven't tested it, but it should work.
Reply With Quote
  #6 (permalink)  
Old 06-21-11, 08:43 AM
Mr_Matijs Mr_Matijs is offline
New Member
 
Join Date: Jun 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Yes,

Thanks a lot !!!
Reply With Quote
  #7 (permalink)  
Old 06-21-11, 09:15 AM
Mr_Matijs Mr_Matijs is offline
New Member
 
Join Date: Jun 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
an other question,




PHP Code:

<?php


$session_username 
$_SESSION['username'];

$filename "file.php"// This is what you want to save the file as.
$content "
     
$session_username
"
// I want $session_username to be in it but it need to be the username of the session like: Paul or something

file_put_contents($filename$content);
?>
Reply With Quote
  #8 (permalink)  
Old 06-21-11, 06:53 PM
Niall's Avatar
Niall Niall is offline
Newbie Coder
 
Join Date: Feb 2011
Location: Kernow
Posts: 85
Thanks: 10
Thanked 3 Times in 3 Posts
Is the username stored in the session? If it is then it would be:

PHP Code:

 <?php 

$session_username 
$_SESSION['username']; 

$filename "file.php"// This is what you want to save the file as. 
$content $session_username;

file_put_contents($filename$content); 
?>
Reply With Quote
  #9 (permalink)  
Old 06-24-11, 05:41 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Quote:
Originally Posted by jamhassan View Post
Sorry but you can visit w3school provide you complete information about php coding lots of the engineer visit daily this site then get extra technique relevant of his subject because that is the important sites who provide you complete information of web development.
That's one site you should stop visiting right now.

W3Fools


Although, I have no idea why you're storing a username in a flat file, but I'm almost sure that's not a good way of accomplishing whatever you're trying to do.
Reply With Quote
Reply

Bookmarks

Tags
.php, edit, file, php


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP or PHP which is better? nepala The Lounge 9 07-14-10 05:48 AM
Write to php file with php script or create new file, it is possible? Oskare100 PHP 10 08-14-08 09:03 AM
PHP displaying in .HTML file tennis4you PHP 6 12-31-06 08:17 PM
Edit Text File with PHP jengels PHP 2 12-07-06 11:04 AM
PHP File Edit Script - Wont work on NT IIS Server mcpaton PHP 1 05-11-04 07:39 PM


All times are GMT -5. The time now is 08:48 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.