I wanna get the page which contains some php and some html code, like this:
Page url: ahax.php?some=1&any=2
Page content:
<?php
some php code
?>
some html
<?php
some php
?>
I always use "echo" in php file for ajax, now it contains more row of html and php code, it is foolish to use "echo".
<?
$url = 'http://www.google.com';
echo file_get_contents($url);
?>
Not sure that I understood what you want to know... however I hope this is what you are looking for. Please, clarify your question.
Also, have a look at this very helpful link.
Related
Specifically I would like the home link to return them to a landing page if they first landed on that landing page. So lets say they land on a city landing page, then they visit other pages on the site I would like if they hit the home page link on those pages to be sent back to the city landing page. Is this possible? If so please explain.
I don´t really understand what you want but you can create logics in php. Use sessions to save wether or not a user visited the site. If you want more information or a better answer write names for the pages and write exactly what the client does and what changes html should have
Edit
It´s not possible in html. You set a php session (for example $_SESSION['site']) to the URL of the site you want the user to return to. You got to use a server and php so you have to save a.html as a.php. Download for example xampp and put your files into the htdocs folder. Start the Apache server.
Lets say you have the follownig:
htdocs/
|- index.php
|- a.php
|- b.php
Add this to the beginning of index.php. This will return the user to the site you put into $_SESSION['site']:
<?php
session_start();
if (isset($_SESSION['site'])) {
header('Location: '.$_SESSION['site']);
exit();
}
?>
This is how you set the session. For example in page b.php:
<?php
session_start();
$_SESSION['site'] = '/b.php';
?>
or in a.php
<?php
session_start();
$_SESSION['site'] = '/a.php';
?>
If you want to delete the session you can for example make a site (htdocs/stop-session.php) with this code:
<?php
session_start();
session_destroy();
header('Location: /');
exit();
?>
Another way is JS but thats far more complicated in my eyes. You could use coockies there.
I hope it helps. If you want any changes comment
I am trying to print a variable from the .gs code within an HTML document using
<?= var ?>
I know I have done this before, but when I do it now, the entire tag is just rendered - so the page displays
<?= var ?>
rather than do anything with GAS.
Yea, that checks out. You CAN use the .createTemplateFromFile with viewport, and must use .createTemplateFromFile not .createTemplateFromFile with any scripting.
Simple enough, just don't use it often enough to keep it all straight.
I am not familiar with PHP Syntax. Now i added JSON Plugin to my wordpress website and activate it.
When i open url to get_recent_post , it's fine. JSON data are showing.
But when i open get_post , it's only showing
{"status":"error","error":"Include 'id' or 'slug' var in your request."}
So i don't know how to add post id to that URL.
here is the pic. Another get_page , gate_date_posts, etc... links are same showing error.
How can i do it?
To display a post's ID, simply use the following PHP code within the WordPress loop:
<?php the_ID(); ?>
To return the ID, use the following PHP code within the WordPress loop:
<?php get_the_ID; ?>
To get a post's id outside of the WordPress loop use the following PHP code:
<?php global $post; $post->ID ?>
Hope that helps you.
http://yoursite.com/api/get_posts/
with the s
If you use the WordPress link and click on it, you will be fine.
I allow myself to ask the question here cause I looked for what to do regarding my problem but didn't find anything helpful.
Im having a webpage where users can modify information such as text, images etc, and I would like to add a button which would save the page as an .html in its current state (reloading the pas reset everything) and upload it on a ftp so they could have access to it online.
At this point, I know how to get all the html content using js .innerHTML, and how to send a file to the ftp using php, but I don't know what to look for to generate the .html file with the innerHTML content in it.
So here I am, asking for your help to guide me toward the right direction.
Thanks a lot!
Following theCNG27's suggestion, I think now the issue comes from my php script.. Sorry about that but Im really not used to php yet.
here is the php script:
<?php
$handle = fopen("filename.html", "w+");
fwrite($handle, $_POST['HTML']);
$dossier = 'endpoint/';
$fichier = basename($_FILES['HTML']['name']);
if(!isset($erreur))
{
$fichier = strtr($fichier,
'ÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÒÓÔÕÖÙÚÛÜÝàáâãäåçèéêëìíîïðòóôõöùúûüýÿ',
'AAAAAACEEEEIIIIOOOOOUUUUYaaaaaaceeeeiiiioooooouuuuyy');
$fichier = preg_replace('/([^.a-z0-9]+)/i', '-', $fichier);
if(move_uploaded_file($_FILES['HTML']['tmp_name'], $dossier . $fichier))
echo 'Upload done !';
}
else
{
echo 'Upload failed !';
}
}
else
{
echo $erreur;
}
?>
it says "no data received"
thanks a lot for the help
So you have Text (in your case the HTML code) in your javascript that you want to transfer to your php script and save it as a file!? Is that correct? If so, I would recommend this:
Since javascript is client-side and php is server-side you should send by POST.
I would use a form like this:
<form name="myform" action="url/to/php/script.php" method="POST">
<button type="submit">Submit!</button>
<input type="hidden" name="HTML" id="htmlsubmit" value="">
</div>
</form>
Now in the js-script you have to update the value of your hidden input like this:
document.getElementById("htmlsubmit").value = htmlcode;
htmlcode represents your HTML code you got through .innerHTML
Now in your PHP script you just have to receive the code and write it to a file:
$handle = fopen("filename.html", "w+");
fwrite($handle, $_POST['HTML']);
Since you already know how to upload a file to ftp via php, just do that with your file "filename.html" ;)
Hope that helps
EDIT: You edited your question and said you need help with the php script... This would be a possible complete script you could use:
<?php
$fname = "filename.html";
if(!isset($_POST['HTML']))
{
echo "Error: No data received...";
}else{
$handle = fopen($fname, "w+");
fwrite($handle, $_POST['HTML']);
fclose($handle);
echo "HTML Code written to file: ".$fname."";
}
?>
Is that all you need in your script?
Using JavaScript, calling innerHTML on the document element will give you the markup of the page as a string, including changes made to the DOM.
var markup = document.documentElement.innerHTML;
Then, you could post this markup to an endpoint using AJAX. The endpoint can receive the string, save it as a html file and then upload it somewhere via FTP.
I have spent WAY too much time searching for this. I know it must be a simple solution so I must be not thinking clearly. here is what I want:
I have some html code and php code in php file.
I perform some logic in php. Based upon this logic, I wish to send the user
to a different web page (url).
I tried the "Redirect", but all I get is an error message about Headers already being sent.
is there a simple solution in HTML or PHP? I also tried looking at the Javascript solution but that needs to be in the header, and this code is in the body.
Thanks for the help. I searched like mad and couldn't find this answer in any OPEN discussions.
John
Your problem is that the PHP code is embedded in your HTML code. When the server reads your HTML code, it begins to send that output to the output buffer. As such, any PHP code that wants to re-direct to a completely new page must come BEFORE any HTML code, or be in a completely separate file, as the buffers cannot be modified once they are already sent.
The easy answer: just make sure your PHP code that does the header() redirect function comes before any HTML code in your file, or put this code in a separate file.
Make sure that header is before any output
Correct
<?php
if ( some condition ){
header('Location: http://www.test.com/');
exit;
}
?>
<htmL>
Incorrect will give error
<htmL>
<?php
header('Location: http://www.test.com/');
?>
In PHP, headers need to be sent before any HTML is displayed. Probably the easiest way to do that is to submit a form:
<?php
// Since this is before the DOCTYPE, you can still send headers.
if (isset($_POST['foo'])) {
header('location: new-url.html');
}
?>
<!DOCTYPE html>
<html>
<!-- rest of the page goes here -->
Chances are you have HTML content before your PHP:
<span>This is HTML!</span>
<?php header("Location: http://www.example.com"); ?>
This won't work because you can't use the header function after having sent output. The HTML code counts as output so the example is the same as:
<?php
echo "<span>This is HTML!</span>"
header("Location: http://www.example.com"); // FAIL
?>
... here the output is very clearly before the execution of header, so it won't work.
It won't work because of the way HTTP responses are structured: headers have to be sent before the response body.
Under the hood, the output of a PHP script is a HTTP response:
HTTP/1.1 200 OK
Content-Type:text/html
<span>This is HTML!</span>
Usually the first line and the headers are added to the response implicitly and your PHP code only outputs the body, but when you use the header function you're adding headers, which have to come before the response body.
This means you have to call header before you output any of the response body:
<?php
header("Location: http://www.example.com");
echo "<span>This is HTML!</span>"
?>
... resulting in something like:
HTTP/1.1 303 See Other
Content-Type:text/html
Location: http://www.example.com
<span>This is HTML!</span>