post web page to php - php

I want to post a whole page using ajax to php file to be parsed.
say the sources is `http://www.mysite.com/page-1.
now post this page (from <html> to </html>) to "parse-page.php". and retrieve it with $_POST['document'].

Considering you just want to post the data and ignore anything coming back from the php, this should work.
$.post("parse-page.php", {'document', $('body').html()});
For more info:
http://api.jquery.com/jQuery.post/

I'm thinking you can use javascript to store the innertext of the html tag and send that variable through ajax.

Related

Using PHP to call jQuery on form submission to $_SERVER['PHP_SELF']

I have a single page of HTML that includes PHP code.
I am using the PHP to send data from a form to the same page using $_SERVER['PHP_SELF'] as the form action.
There is an isset($_POST... condition in the PHP that detects if the page has loaded with data via POST. If this is true, the PHP compares the value sent to a set maximum value.
If the data is less than the maximum value, a table is displayed.
If the data exceeds the maximum value, I would like to display an error message using jQuery: $('.error_box').append("Error");
The error message is not displaying. I think this is because the PHP is trying to make changes to .error_box before it has loaded.
How can I make sure that the error display function is available, given that I am validating the form data via PHP as soon as the page loads?
You don't have to use javascript or jQuery to add content to '.error_box'
You should add it with PHP directly.
EDIT:
You must know that you can't directly execute javascript via PHP.
Here is how your page is created then rendered (this is simpler than reality) :
Your server receive the request to display a page
The PHP code is executed and output an HTML (+CSS +JS) page
The output is send back to the client who ask for page
The client browser parse the HTML and render it using css rules you specified
The javascript is executed
Wrap it in a document ready function, like so:
$(document).ready(function() {
$('.error_box').append("Error");
});
Edit:
AMDG is probably right also...

Refresh Div Containing PHP Function

So I have the following code:
<div id="currentmotto"><?php mottoGrab($name); ?></div>
And what this does is it uses curl to screen scrape a users motto and display it on the site. What I need it to do is for that function to refresh every few seconds to see if the user has updated the motto.
I know with jquery I can use the .load('phpfile.php') but the problem then is if I put that function in that file, it no longer gets the $name variable as that is from another page.
Any ideas?
Pass name to phpfile.php via the query string:
.load('phpfile.php?name=THENAME');
Then grab the name from within phpfile.php using $_GET['name'] and stick it in the function.
OR
Make an AJAX request passing the name and update the page using javascript.
Since PHP is executed server-side, it doesn't change once the client loads the page. The only way to refresh a div without JavaScript is to reload the page.
I would try using AJAX to get the name from the other file and update the HTML with JavaScript

Pass data from PHP directly to DOM variable

I'd like to pass some data from PHP to JavaScript without JSON.
The reason is because I don't want the data been readable by anyone if clicks on view page source.
So, I have a PHP like
print(<script type="text/javascript">a = "aaa";</script>);
In my HTML code this will be
<script type="text/javascript">a = "aaa";</script>
I can remove this in the client side, after loading the variable. By for example with jquery
$('script[type="text/javascript"]').remove();
And after the DOM will not have anymore the script tag, but the variable a.
Later if I type to the console window.a will be aaa.
But i do not want to show the <script type="text/javascript">a = "aaa";</script> in my HTML source code. Is this possible, to pass the PHP variable directly to the DOM?
Thanks for the help.
JavaScript is a client-side language. Whatever you pass to it (by whatever means) will be readable by the end user.
Removing the Script DOM won't help, as "view source" shows the HTML code as it was during download. If that is what you are concerned about, you can fetch the variable via an AJAX once the DOM has been loaded.
(But it still is readable by anyone who can read JavaScript (an re-run the AJAX call), use Firebug or Wireshark. It really only helps against a simple "view source".)

Getting source code from page AFTER jQuery function in PHP

I'm trying to get the source code from this page, to get the code of the timetables, and then parse it.
But when I fetch it with file_get_contents, the div I'm looking for is empty. I searched in the code, and it looks like it's filled with jQuery when to body is loaded.
So my question is : how can I get the source code of the page after the jQuery is executed ?
Thanks.
Since jQuery is javascript, php's file_get_contents will not help because it does not execute javascript.
Either find out which ajax data they load and use them directly, or use a browser ;)
the information you want comes from this page http://www.cinesion.ch/cinesion/timetable.php through an AJAX request so file_get_contents will never get it unless you do the call directly to this page...
try this one
http://www.cinesion.ch/cinesion/timetable.php?date=%&movie=%&city=%&_JEXEC=1

Have html in a string - need to show it as a separate html page using code

I have a script which takes in html from the user as in full page html either from the user or grabs it via curl or from an email. The thing is that I have the html in a string but on the same page I need to show the htmnl in a separate iframe. I don't want to reput any database, curl or imap code in the page referenced by teh iframe at all - is there a way for me to show html passed into a url somehow? like as in a get variable .. the html can be huge here... sorry if it sounds weird.
You can put the grabbed html into a temp file and put the link to that temp file into the src="" of the iframe.
Create them using tempnam(), then create a small script that gets the (preferably obfuscated) filename and simply prints it out if it was really a temp file created by you.
Be careful! if it doesn't check the filename well, you are giving full read access to your server... Put the link to this script in the src of the iframe. You can also create temp files in the public folder of your www server, but I wouldn't want temp/garbage there.
(if i am not misunderstanding your question)
You could put the string in a textarea inside a form and submit the form ..
the receiving page would read the posted data and render it on the page..
I'm not quite sure what you want to do, put you could always post the string as a POST variable, no limitations on how long they can be.
You can encode pieces of HTML with urlencode which is automatically decoded when you retrieve it with $_GET or you can use e.g. base64_encode and base64_decode. The problem is that there are limits to $_GET and $_POST. Both can be set in your configuration settings, but sending large amounts of data via the URL is really not-done because that's not how it should be used.
But if I read your question correctly, you can fetch the HTML at the top of the page, and then load it into an iframe?
if ($_GET['url']) {
$html = file($_GET['url']);
}
if ($_POST['html']) {
$html = $_POST['html'];
}
And then include it:
<html>
..
<iframe ..><php echo $html; ?></iframe>
..
</html>

Categories