Check if file is being run on server [closed] - php

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
I have a html file which has a link to php file. When i run the html file and click on php link source code of page is being shown as i'm not running on server. Is there a way we can check whether it is running on server and show a message like "Please run it on server" instead of showing source code. Searched a lot but didn't find anything on this topic . How can i do this?

No. If there's no PHP interpreter installed there's no way to run PHP script to check that and tell you that you need PHP interpreter installed first to run PHP script....

actually you cannot check this, but you can make some kind of workaround
at the very top of your php file add following code:
<?php
if (false) {
?><script>
alert('php is not on server!!!');
document.location.href='http://MYSERVERADDRESS/';
</script><?php
}

Not really. Sure, for sport I can think of something, but really, you shoudn't be in this situation.
sporthack: what you are trying to do is make non-interpreted code be hidden, and an error be shown. Be sure to realise the non-interpreted code will always be there in your source, so you have to 'hide' it.
Make all content available only via javascript. Also, define a javascript tag with a var via a php echo command.
Then, only show your code when the javascript var is set, otherwise show your desired error. Make sure all your code is 'behind' an include, so you don't show that.
Yeah. this'll take a bit of work to make pretty, so you'd be hard-pressed to even get it off the ground.

Related

How do I get information from this page, that isn't in the HTML code [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
http://www.aliexpress.com/item/NEW-7-Android-2-3-256MB-DDR2-4GB-NAND-Flash-7-inch-tablet-pc/498159194.html - I got this link
Here you can see a buttons: bundle, color
If you click some of them the price will change, but the question is how can I parse that behaviour to my page via php?
The problem is that I can't understand where is javascript code that executes this, or how to find it, maybe someone got ideas about that?
Inspecting that page's source code I can see that the skuProducts variable in javascript contains this information encoded into a JSON-string. You can't really run this javascript code on your webserver, so you'll have to devise another way to get that variable's value - and then you can use json_decode() to get the contents.
Note that changing the amount of items results in an AJAX call to a shipping costs calculator. You could probably simulate that, but I'm not sure that webshop would like that (and it might be illegal).

Get the source code of a web page after it has been modified by jquery in php [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
here is an example, say every item in each list was clicked on http://katproxy.com/the-big-bang-theory-tv8511/, how would you proceed to get the source code of the modified web page using php considering the fact that the url has not changed (file_get_contents is probably out of the question).
Thank you!
Using PHP? You can't, not without fetching the page source and evaluating its JavaScript, which is obviously quite impractical.
The "page" hasn't change, only your in-browser representation of the DOM has been modified. You would need PHP to talk to your browser, and ask for the state of its DOM, not the remote server, which cannot possibly serve up the HTML representation of your browser's current DOM.

PHP,Linux,Apache: naming file based on user input [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Improve this question
whats up guys?
so my question is simple: my application receives the name of the file as a $_POST['fieldname'] from user and then create the file in a folder on server, or in another case using the $_POST['fieldname'] return the path of the file if file exists. so, is it safe?!
thank you guys!
The answer is that it depends on how well you set up the security around your filesystem access and how you serve the files. If you are only allowing them to send information to a particular folder and you're sanitizing the input, you could be fine. Here's more info on basic filesystem security from php.net. However you want to make sure they can't php code in files and execute them directly. A good bet there would be to not allow any execution from that folder using .htaccess.
However, as the top comment on that php.net link says, you should really consider not letting your users name files, and you should think about trying to store as much in a database as possible.

Echo Execute PHP Code [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is it possible to execute PHP code in echo? I need this to finish my work, but everything I try seems to be fruitless; I often bump to either blank browser page or some errors.
It does not need to be with echo func. Here is example of the code I would like to compile. Just a sample nothing flashy. Echo is just example, I would like to put more complex and advanced code at echo's place but I would like to start from simple stuff like that.
<?php $code = "<?php echo '123'; ?>" echo $code; ?>
That is....an epic fail catastrophe. But for whatever reason, I'm answering... You would need to use eval(). But don't do it. Read here: http://php.net/manual/en/function.eval.php
Perhaps you just need to use include 'path/to/file/with/my/code';. Read here: http://php.net/manual/en/function.include.php
Based on your comments, I think you're actually looking for this:
echo htmlspecialchars(file_get_contents(__FILE__));
That will display the php code that ran. You could search for that line and remove it before displaying. You could even write a function to look at all of the included files and add them to a $variable to be displayed, using the same logic.
Php is only executed on the serverside, so when you try your echo code, you are saying print this code. If you want your code to validate/run logic after it has been server from the server, i would recommend looking into javascript and AJAX requests.
Good luck :)

How can I store data from MySQL into html using php? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions must demonstrate a minimal understanding of the problem being solved. Tell us what you've tried to do, why it didn't work, and how it should work. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
This is something I need help on.
Im going to allow a user from my database to "share" a record which gets sent from the database into a solid html file.
So I'm looking at ways to create a html file from data in a database which is passed through php and stored in a location on the server. with no interaction from the user at all other than pressing 'share'. They would be sent the url to look at it upon success.
I'm looking for any functions or tuts on how to best make a html file from php. any help is appreciated. I think I may be looking into this too much, and the answer may be staring me in the face
As it got clear, you want static html files, created dynamically via PHP and written on the server.
The steps you need to follow are clear too:
You need the database and as you said you have it
You need to connect to it via PHP
Then do the respective queries
Fetch the data from them
Use it in the HTML
Open a file
Send the used data to it
Write the file with the relevant name
The querying should start after the button share is clicked (you can track this via isset() function)

Categories