I'm very new to PHP so maybe its a very simple question.
One page1.php I want to show the url of page2.php
I tried it like this:
One page1.php:
<?php
$url1="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
?>
On page2.php:
<?php
echo $url1; ?>
Its a wordpress installation so I need url with permalinks.
maybe its a noob question but I only need to know how this works.
Thanks!
You should put them running one time, then page2.php can receive the url.
For example: in page2.php, include page1.php before echo.
So in page2.php:
<?php
include 'page1.php';
echo $url1; ?>
There are a few alternative solutions for that. I'd advice using file_get_contents function.
Example usage:
$url1 = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$page1 = file_get_contents($url1);
echo $page1;
See more details here:
http://php.net/manual/en/function.file-get-contents.php
Related
I have been struggling with this for a while now.
What I found is this:
<div id="include"></div>
<script>
$(function(){
$("#include").load("/test.php");
});
</script>
This does work when in test.php is a simple code like:
<?php echo 'echo world'; ?>
But it doesn't work when I want to grab Wordpress variables.
<?php $current_user_id = $current_user->ID;
echo $current_user_id; ?>
There's nothing outputed. No error. Just a blank.
It's like it doesn't send the variables to the test.php. So test.php doesn't echo values filled. When I use <?php include 'test.php';?> it does fill the variables and works as I wanted.
So basically, .load simply loads the file.
But I want <?php include;?> to be executed instead of .load.
When I use <?php include;?> I can grab variables, which I need.
Is there other command instead of .load to do that?
Any help would be appreciated.
Okay, so I have two pages, home.php and page.php. On home.php, I load page.php onto it using jquery. In the url of home.php there is a GET value, u. I want to access that GET value on page.php. You can see that I tried the regular $_GET method, but this does not work. If on page.php I can just get the url of home.php with the GET variables in the url, I can get the info from there. But right now I cannot get the url of home.php, it just gets page.php. I hope that makes sense and thanks for the help!
Home.php
<div id='holder'></div>
<script>
$('#holder').load('page.php');
</script>
Page.php
<?php
$u = $_GET['u'];
echo $_SERVER['PHP_SELF']; // echo's "page.php". I need it to echo "home.php?u=test"
//some php
?>
What you can do is pass the $_GET variable to the requested page.
Do it like this:
<div id='holder'></div>
<script>
$('#holder').load('page.php<?php echo "?u=" . $_GET[" u" ]; ?>');
</script>
Stackoverflow doesn't parse it the way I want but I'm sure it works.
so I have:
$url = unserialize(base64_decode($info['story_frame']));
print $url->html;
On my php page but want to be able to format the printed code and chose where in the html it goes. Any Ideas?
You can also require the above page in the other html page.. anyways for even requesting the POST object, u have to anyways convert it to a php page. So now u have two ways of achieving it..
One requesting the POST object.
i.e
first phppage
<?php
$url = unserialize(base64_decode($info['story_frame']));
?>
<form action="urhtmlpage.php" method="post">
<input type="hidden" name="url" value="<?php echo $url ?>">
</form>
destination php page
<?php echo $_POST['url'] ?>
Requiring the other page in your new page.
first phppage
<?php
$url = unserialize(base64_decode($info['story_frame']));
?>
destination php page
<?php
require("yourphppage.php");
echo $url;
?>
But for both ways convert your HTML page into PHP page
You should probably make that other html page a php page and then request post.
Post to another page within a PHP script
Let's say you put this code in a page called "print.php".
On the code which you would want to put the output on, try the following:
<div class="formatMe">
<?php include 'print.php'; ?>
</div>
You will be able to move the div around as you please, and the content will move with it.
Is there anything in PHP that is the equivalent of manually pressing the F5 page reload button? My php script is in a frame and isn't the parent script but it needs to refresh the entire page and not just it's frame.
Actually it is possible:
Header('Location: '.$_SERVER['PHP_SELF']);
Exit(); //optional
And it will reload the same page.
With PHP you just can handle server-side stuff. What you can do is print this in your iframe:
parent.window.location.reload();
If you have any text before a
header('Location: http://www.example.com/youformhere.php');
you'll have issues, because that must be sent before any other text is sent to the page.
Try using this code instead
<?php
$page = $_SERVER['PHP_SELF'];
echo '<meta http-equiv="Refresh" content="0;' . $page . '">';
?>
Just remember, this code will create and infinite loop, so you'll probably need to make some conditional changes to it.
PHP cannot force the client to do anything. It cannot refresh the page, let alone refresh the parent of a frame.
EDIT: You can of course, make PHP write JavaScript, but this is not PHP doing, it's actually JavaScript, and it will fail if JavaScript is disabled.
<?php
echo '<script>parent.window.location.reload(true);</script>';
?>
<?php
echo "<script>window.opener.location.reload();</script>";
echo "<script>window.close();</script>";
?>
with php you can use two redirections.
It works same as refresh in some issues.
you can use a page redirect.php and post your last url to it by GET method (for example).
then in redirect.php you can change header to location you`ve sent to it by GET method.
like this:
your page:
<?php
header("location:redirec.php?ref=".$your_url);
?>
redirect.php:
<?php
$ref_url=$_GET["ref"];
header("location:redirec.php?ref=".$ref_url);
?>
that worked for me good.
Use JavaScript for this. You can do:
echo '
<script type="text/javascript">
parent.window.location.reload(true);
</script>
';
In PHP and it will refresh the parent's frame page.
guess you could echo the meta tag to do the refresh in regular intervals ... like
<meta http-equiv="refresh" content="600" url="your-url-here">
All you need to do to manually refresh a page is to provide a link pointing to the same page
Like this:
Refresh the selection
Adding following in the page header works for me:
<?php
if($i_wanna_reload_the_full_page_on_top == "yes")
{
$reloadneeded = "1";
}
else
{
$reloadneeded = "0";
}
if($reloadneeded > 0)
{
?>
<script type="text/javascript">
top.window.location='indexframes.php';
</script>
<?php
}else{}
?>
Hi i am not a php developer, ive never touched it before. but i have been asked to add a google shopping cart tracking code to a website. when someone completes an order then get sent to finishorder.php. when i go the finishorder.php file it looks like this:
include(dirname(__FILE__)."/init.php");
$GLOBALS['ISC_CLASS_ORDER'] = GetClass('ISC_ORDER');
$GLOBALS['ISC_CLASS_ORDER']->HandlePage();
which just looks like server script to me (coming from a .net background), so i presume i cannot add the javascript here, how does php decide get the layout for this page? how can i add the javascript code to this page.
You can do this:
include(dirname(__FILE__)."/init.php");
$GLOBALS['ISC_CLASS_ORDER'] = GetClass('ISC_ORDER');
$GLOBALS['ISC_CLASS_ORDER']->HandlePage();
echo '<script type="text/javascript">YOUR JS HERE</script>';
OR
<?php
include(dirname(__FILE__)."/init.php");
$GLOBALS['ISC_CLASS_ORDER'] = GetClass('ISC_ORDER');
$GLOBALS['ISC_CLASS_ORDER']->HandlePage();
?>
<script type="text/javascript">YOUR JS HERE</script>
Hmm?
But I think that HandlePage() method will do something with our page so I'd look inside this method Class ISC_ORDER->handlePage() what it does... You can then echo Your within this method on appropriate place...
EDIT:
<?php
echo '<script type="text/javascript">//<!--
alert("Hello to multiline JS script");
alert("Do You get it?");
//--></script>';
?>
You can add javascript inside a php code as
<?php echo "<script> alert('this is a javascript code')</script>"; ?>
You can add script in PHP page by 2 ways
The first way is to add it in PHP tags
<?php
//PHP CODE
if($_POST['submit']){
echo '<script>alert('Hello')</script>';
}
?>
The second way is to add it after PHP code
<?php
//PHP CODE
?>
<script>
alert('Hello');
</script>