Jump to content

[SOLVED] any work around?


kucing

Recommended Posts

Hello there,

 

I want a function or a command which let me read a php file but should not run it while reading.

 

like example.

 

I have a file name read.php

 

read.php

<?php
echo ("hello");
?>

 

When I get the content of this file using file_get_contents which first run the file and then I get the content of the file

 

I only want to have the content of this file without running this file.

 

Thanks.

Link to comment
Share on other sites

So you there to be a php file, we'll call it test.php. You want to be able to do a function that will read its php code(not the resulting html it outputs) and display it in some form? Ummm... if there's a way, then facebook and other big sites that run in php would be easily hacked. I don't know of a way to do that.. unless there are some hacker tools out there.

Link to comment
Share on other sites

<?php
$file = 'somefile.txt';
$handler = fopen($file, 'r');
$contents = fread($handler, filesize($file));
print $contents;
fclose($handler);
?>

I think that's what you're looking for.

 

he's looking to read a .php file. not a .txt(or any other) file.

Link to comment
Share on other sites

its correct code.

just change file name to read.php.

dats all.

<?php
$file = 'read.php';
$handler = fopen($file, 'r');
$contents = fread($handler, filesize($file));
print $contents;
fclose($handler);
?>

 

Precisely, fopen() can read any kind of file. I use it often to read .torrent files and use my BEncode library I wrote to get the Meta-Info from it. However, you won't be able to write to this file without the necessary permissions on the server.

 

Link to comment
Share on other sites

its correct code.

just change file name to read.php.

dats all.

<?php
$file = 'read.php';
$handler = fopen($file, 'r');
$contents = fread($handler, filesize($file));
print $contents;
fclose($handler);
?>

 

 

 

uhhh... have you tested your code? He's saying he wants the code(I believe), not the output. Or I may have misread. He wasn't clear anyways when he said he wants the content of the file. Since php has code, and then changes to show html, if you to that with .php, if will give you the html that would otherwise be shown if you viewed the file

Link to comment
Share on other sites

No I haven't tested my code. And I do not need to because I know it works. It will write the contents of any file you specify into the browser in plain text. However, it will NOT be formatted like it would when opening the file in a text editor. You will need to write additional code to accept the line breaks.

 

It won't display the output of the PHP file which is being read because that particular code isn't being parsed by the PHP Engine, the read code is.

Link to comment
Share on other sites

may be i misinterpret him,but if you want to show the code, of course not in html form. then Wolphie code is correct.

try it yourself.

just tried:

$sql="SELECT * FROM xyz where active ='0'"; $q=mysql_query($sql); $num=mysql_num_rows($q); while ($row = mysql_fetch_object($q)) { $id=$row->id; $ch1=$row->ch1; $ch2=$row->ch2; $ch3=$row->ch3; $chp1_2_3=$row->chp1_2_3; $active=$row->active; echo $id; $sql1="update xyz set active='1' where id='$id'"; $q2=mysql_query($sql1); } ?>

 

Link to comment
Share on other sites

Thanks all for your time and concern.

 

Well.. I am still getting the same result as if using file_get_contents function.

What if we change the first line <?php to ?php while getting the data from the file or rename the file to .txt ext before getting the content?

 

any easy way to do that?

 

Thanks

Link to comment
Share on other sites

may be i misinterpret him,but if you want to show the code, of course not in html form. then Wolphie code is correct.

try it yourself.

just tried:

$sql="SELECT * FROM xyz where active ='0'"; $q=mysql_query($sql); $num=mysql_num_rows($q); while ($row = mysql_fetch_object($q)) { $id=$row->id; $ch1=$row->ch1; $ch2=$row->ch2; $ch3=$row->ch3; $chp1_2_3=$row->chp1_2_3; $active=$row->active; echo $id; $sql1="update xyz set active='1' where id='$id'"; $q2=mysql_query($sql1); } ?>

 

 

did you have a beginning <?php in that code? And did you upload it to a server in .php format? And when you ran the script, did it read the php code or the output in html format? I know what the answer is. Neither of us are wrong in this thread, we are just both interpreting the guy's question differently. There is no [easy] way to get pure php code from a .php file(if that's what he's asking)

Link to comment
Share on other sites

Except showing <?php i upload to server. read another file in that file.

and works.

may be he want to show all the code and with breaks.so has to do extra coding for that.

 

 

you didn't answer my question. Is the file a valid .php file, and you are using fopen to read the php code?

Link to comment
Share on other sites

No offense dannyb785, but you're criticizing peoples code and their efforts to help this person. Yet what exactly have you contributed? Apart from idiotic criticism.

If you're going to do that, make sure it's constructive criticism which will help people better their programming skills. Not everybody has an extensive experience.

Link to comment
Share on other sites

No offense dannyb785, but you're criticizing peoples code and their efforts to help this person. Yet what exactly have you contributed? Apart from idiotic criticism.

If you're going to do that, make sure it's constructive criticism which will help people better their programming skills. Not everybody has an extensive experience.

 

Hey wolphie, wanna show me where I was idiotic? Also, show me where I told him his code was wrong. His code performs a task. I didn't think, based on the initial question, that the code provided performed the task requested. I was the first person to reply and post help! That's what I contributed. I also contributed the fact that you can't gather php code from a php file uploaded to a server just by running a fopen script.

Link to comment
Share on other sites

How does posting first justify it? And if you read, correctly. I wasn't suggesting his code. You didn't provide any evident help which could prove useful to the person asking the question, it's not exactly considered as a contribution. And by idiotic I meant your attitude, alright yes, you made a point which could have been put across better. But you didn't provide a solution. All in all, he didn't use the original method I proposed so therefore, discussion closed.

Link to comment
Share on other sites

How does posting first justify it? And if you read, correctly. I wasn't suggesting his code. You didn't provide any evident help which could prove useful to the person asking the question, it's not exactly considered as a contribution. And by idiotic I meant your attitude, alright yes, you made a point which could have been put across better. But you didn't provide a solution. All in all, he didn't use the original method I proposed so therefore, discussion closed.

 

 

How about my input being ignored? I said that if you're trying to grab pure php code from a php file off of a server, you can't do it. How much better does it need to be put across? I didn't provide a solution bc there wasn't one.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.