Follow us on Twitter!
Things are more like they are now than they have ever been before. - Dwight D. Eisenhower
Wednesday, April 23, 2014
Navigation
Home
HellBoundHackers Main:
HellBoundHackers Find:
HellBoundHackers Information:
Learn
Communicate
Submit
Shop
Challenges
HellBoundHackers Exploit:
HellBoundHackers Programming:
HellBoundHackers Think:
HellBoundHackers Track:
HellBoundHackers Patch:
HellBoundHackers Other:
HellBoundHackers Need Help?
Other
Members Online
Total Online: 21
Guests Online: 21
Members Online: 0

Registered Members: 82885
Newest Member: ConiBE
Latest Articles
View Thread

HellBound Hackers | Computer General | Webmasters Lounge

Author

problem with fopen and fwrite


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 27-05-07 21:48
Code
<?
$name = $_POST['name'];
$content = $_POST['content'];
$url = $_POST['url'];
$ext = $_POST['ext'];
$fullurl = $url."".$ext;
$ourFileName = $fullurl;
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
$myFile = $fullurl;
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $content;
fwrite($fh, $stringData);
fclose($fh);
?>




When ever the value of $content contains php the file contains the php in plaintext :( like echo (\"hello world\");

erm ....
Help me please!!
ty
Dotti.


Author

RE: problem with fopen and fwrite


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 27-05-07 21:51
or these errors


Warning: Unexpected character in input: '\' (ASCII=92) state=1 in C:\xampp\htdocs\functions\test.php on line 2

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in C:\xampp\htdocs\functions\test.php on line 2

Warning: Unexpected character in input: '\' (ASCII=92) state=1 in C:\xampp\htdocs\functions\test.php on line 2

Parse error: syntax error, unexpected $end in C:\xampp\htdocs\functions\test.php on line 3


Author

RE: problem with fopen and fwrite


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 27-05-07 21:53
djdotti wrote:
Code
<?
$name = $_POST['name'];
$content = $_POST['content'];
$url = $_POST['url'];
$ext = $_POST['ext'];
$fullurl = $url."".$ext;
$ourFileName = $fullurl;
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
$myFile = $fullurl;
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $content;
fwrite($fh, $stringData);
fclose($fh);
?>




When ever the value of $content contains php the file contains the php in plaintext :( like echo (\"hello world\");

erm ....
Help me please!!
ty
Dotti.


Couple things: disable the smilies so it's easier to read. Second, what are you trying to achieve? Because it seems that the file from which you're reading from is a variable so it will be difficult to help you without more information. You should probably also post the HTML form you're using :)


Secondly, it would probably be beneficial to use <?php instead of <? at the start of your code :)

Edited by on 27-05-07 21:55
Author

RE: My full script ...


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 27-05-07 21:55
newfile.htm :
Code
<html>

<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
</head>

<body>

<form method="POST" action="functions/newfile.php">
   <p align="center">Filename :<br><input type="text" name="name" size="30"></p>
   <p align="center">Url :<br><input type="text" name="url" size="30"><select size="1" name="ext">
   <option value=".php">.php</option>
   <option value=".htm">.htm</option>
   <option>.html</option>
   <option value=".txt">.txt</option>
   </select></p>
   <p align="center">Content :<br><textarea rows="10" name="content" cols="90"></textarea></p>
   <p align="center"><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>

</body>

</html>



newfile.php :
Code
<?
$name = $_POST['name'];
$content = $_POST['content'];
$url = $_POST['url'];
$ext = $_POST['ext'];
$fullurl = $url."".$ext;
$ourFileName = $fullurl;
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);
$myFile = $fullurl;
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $content;
fwrite($fh, $stringData);
fclose($fh);
?>





Author

RE: problem with fopen and fwrite


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 27-05-07 21:57
if I understand correctly, it looks like you need to use stripslashes(), I think you'd put it here
Code
fwrite($fh, stripslashes($stringData));






Author

RE: problem with fopen and fwrite


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 27-05-07 21:59
Again, what are you trying to achieve excactly? We can guess around all day but it won't help you much Frown

(I mean I made the files, uploaded it to my server and I'm still kind of puzzled as to the objective).

Edited by on 27-05-07 22:00
Author

RE: problem with fopen and fwrite


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 27-05-07 22:00
xtrmsk8r91 wrote:
if I understand correctly, it looks like you need to use stripslashes(), I think you'd put it here
Code
fwrite($fh, stripslashes($stringData));




:o:O:O:O:O:O:O:
00OH ty sk8r! You rock ... I owe ya ;)


Author

RE: problem with fopen and fwrite


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 27-05-07 22:10
lol no problem, glad it worked Smile


Author

RE: problem with fopen and fwrite


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 27-05-07 22:37
if all you are doing is opening up files, just use

read:
Code

file_get_contents("file.txt");





write:
Code

file_put_contents("file.txt",$contents);





kills the whole opening file handles deal. one nice command to do it all for ya.




Edited by on 27-05-07 22:37
Author

RE: problem with fopen and fwrite


Member

Your avatar

Posts:
Location:
Joined: 01.01.70
Rank:
Guest
Posted on 27-05-07 22:49
im writing data to a file ... But sk8r has sorted it now thankyou
Dotti.