Load in random .html file with PHP? [closed] - php

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
I have a folder which contains several html files: 1.html, 2.html, 3.html, etc., etc. in sequential order.
I would like for PHP to randomly load in these files into a PHP webpage that I have. How can I go about doing this?
Also -- is PHP the most efficient way to do this? Would jQuery be better?

jquery could do it, but you'd have to send a list of the available files to the client beforehand, so it has a list to choose from. This would be required if you can't guaranteed there'll never be "holes" in the files, e.g. 1,2,4,5 (hey, where's 3?).
PHP can deal with the raw filesystem, and can always get the list of files, e.g.
<?php
$files = glob('*.html');
$random_file = $files[array_rand($files)];
include($random_file);
This will handle any .html file, regardless of holes in the numbering sequence, or even if they're numbered at all.

Related

Can I find what files are using when a website page is ran? [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
I just received a source from my customer (it's written by PHP Generally), I try to read it and glance at database. I realize that it's very mess, some webpage's content is also saved in database. So, I want to find files are using by browser and I mean that php files, I want to edit them. Can I do that?
P/S: I'm sorry if this article bother you
Hi At any point you need to know what functions, what includes and what arguments are being passed just use debug_print_backtrace() function in your code.
for further reading follow http://www.php.net/manual/en/function.debug-print-backtrace.php

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.

fetching from text file or database? [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
I have to display data consisting of approx. 1000 character.
Right now, I am using a text file and fetching it from there line by line till end of file and displaying it through AJAX.
But its quite slow.
I wanted to know if i store that data in database as text would it make difference ?
Yes. It does depend on how many lines there are tho. If there aren't many lines, it won't make much of a difference.
I would recommend (for something small) a txt file on the server and directly getting it directly with AJAX, without the addition step of php and sql.
You shouldn't need to read line by line. You can read the full string with:
file_get_contents('/path/to/file')
I cannot foresee storing the text in a single database row/field will improve efficiency at all.
actually storing text in database can slowdown performance, looks like your problem is in line-by-line reading, read about file_get_contents or file or the best way readfile

counting the number of times a script is executed [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
I have got two php forms - question.php and marks.php. I want that each time question.php submits its values to marks.php , the variable $total in the form marks.php be incremented. I have tried using static variable but still am not able to get it done!
Nothing "inside PHP" itself will persist anything across different page loads. You need to store the value somewhere "external", e.g.:
write it to a file
write it to a database
store it in a memcache or other kind of cache
send it to yourself in an email
burn it into the screen of the computer and use an elaborate video camera and OCR setup to read it back
...
maybe: sessions

Categories