PHP - auto refreshing page - php

I am using following code for a refreshing page, it is not reloading on completion. The following code is not working sometime.
$page = $_SERVER['PHP_SELF'];
$sec = "10";
header("Refresh: $sec; url=$page");
echo "Watch the page reload itself in 10 second!";

Use a <meta> redirect instead of a header redirect, like so:
<?php
$page = $_SERVER['PHP_SELF'];
$sec = "10";
?>
<html>
<head>
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
</head>
<body>
<?php
echo "Watch the page reload itself in 10 second!";
?>
</body>
</html>

you can use
<meta http-equiv="refresh" content="10" >
just add it between the head tags
where 10 is the time your page will refresh itself

use this code ,it will automatically refresh in 5 seconds, you can change time in refresh
<?php
$url1=$_SERVER['REQUEST_URI'];
header("Refresh: 5; URL=$url1");
?>

Try out this as well. Your page will refresh every 10sec
<html>
<head>
<meta http-equiv="refresh" content="10; url="<?php echo $_SERVER['PHP_SELF']; ?>">
</head>
<body>
</body>
</html>

Maybe use this code,
<meta http-equiv="refresh" content = "30" />
take it be easy

This works with Firefox Quantum 60+ and Chrome v72 (2019)
//set a header to instruct the browser to call the page every 30 sec
header("Refresh: 30;");
It does not seem to be NECESSARY to pass the page url as well as the refresh period in order to (re)call the same page. I haven't tried this with Safari/Opera or IE/Edge.

Simple step like this,
<!DOCTYPE html>
<html>
<head>
<title>Autorefresh Browser using jquery</title>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(function() {
startRefresh();
});
function startRefresh() {
setTimeout(startRefresh,100);
$.get('text.html', function(data) {
$('#viewHere').html(data);
});
}
</script>
</head>
<body>
<div id="viewHere"></div>
</body>
</html>
This video for complete tutorial
https://youtu.be/Q907KyXcFHc

<meta http-equiv="refresh" content="10" >
This can work. Try it..!! :-)

Related

Is there a way to change default link in php?

The default link I get is to link index.php.
How can I change the default link to all my project to index.php?folder=0?
You can check GET starting in index.php file.
If $_GET['folder'] is not set then redirect otherwise load same page.
if(!isset($_GET['folder'])){
header("Location:./index.php?folder=0");
}
Hope this work to you.
You could do something like this...
<?php
$sec = 0;
$page = '?folder=0';
?>
<html>
<head>
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
</head>
<body>
</body>
</html>

how to make php variables show in loaded content

tried to ask this question earlier but made a total mess of it. so thought i'd try it again but clearer this time.
how can you get php variables to display in loaded content using JQuery?
index.php:
<!doctype html>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script>
$(document).ready(function(){
$('#clickMe').click(function(){
$('#parent').load('loaded.php #child', {},function(){
});
});
});
</script>
</head>
<?php
session_start();
$test = "this should display php string";
$_SESSION['another'] = "Session variable String";
echo ' tests to see if they work below <br>';
echo $test."<br>";
echo $_SESSION['another']."<br><br>";
?>
<button name="clickMe" id="clickMe" class="clickMe">Click me</button>
<div class="parent" name="parent" id="parent" style="background-color:yellow; height:200px; width:200px;">
</div>
<body>
</body>
</html>
loaded.php:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<div name="child" id="child" class="child">
<p1> html loads fine..</p1><br>
<?php echo $test ?><br>
<?php echo $_SESSION['another'] ?>
</div>
</body>
</html>
As stated by #Fred -ii- in the comments, you only have to fetch the session in your index.php file to do this.
If you want to get a part of another web page inside index.php :
Your index.php should contain this call :
$(document).ready(function(){
$('#clickMe').click(function(){
$('#parent').load('loaded.php'); // No need for additional parameters
});
});
You don't need to select a part of the HTML, return just what you need :
loaded.php :
<?php session_start() ?>
<p>Example text</p>
<?php echo $_SESSION['another'] ?>

Add Wordpress Iframe of 3rd party company which provide me search, and search results page

Yes, I know something like this has been asked over here before and I have searched but the one that is closest to what I'm trying to achieve doesn't have an answer anywhere.
So what I need is really simple.
I have a WordPress site and I want to integrate Iframe of 3rd party company which provide me search, and search results page.
I need some help with put the search on section and the search results on hidden field or somthing until we have some results to show.
I have got 2 pages from 3rd party company as follow:
Search.html
<pre>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8" />
</head>
<body>
<iframe src="http://www.3rd_party_url/Default.aspx?urlresult=http://www.3rd_party_url/result.html" scrolling="no" width="350px" height="280px"></iframe>
</body>
</html>
</pre>
Result.html
<pre>
<html >
<head>
<title></title>
<meta charset="utf-8" />
<script type="text/javascript">
function GetQuery() {
var url = window.location.href;
url = url.substring(url.indexOf("?"))
iframe = document.getElementById('myIframe');
iframe.src = "http://www.3rd_party_url/pleasewait.aspx" + url;
}
window.onload = function ()
{
GetQuery();
}
</script>
</head>
<body>
<iframe id="myIframe" width="100%" height="800px" src=""></iframe>
</body>
</html>
</pre>
Not sure how to move on from there. I'd really appreciate some help.
Thanks in advance!

Simple Redirect Page With Click Button To Continue

I need to create a dynamic redirector page that I can put ads banner and a call button that appears after 5 seconds. When I click the button, it will redirect to any URL after ?
For example :
1 - user click a link in website :
- http://www.mydomain.com/go.php?http://www.google.com
2 - go.php loads a landing page with 5 seconds countdown timer show up
3 - after 5 seconds, a button appears...user can click the button to go to actual link
I manage to get the simple code..but I don't want it to automatically redirect...
<?php
$redirect = $_SERVER['QUERY_STRING'].'';
?>
<html>
<head>
<meta name="robots" content="noindex" />
<meta http-equiv="content-type"
content="text/html; charset=ISO-8859-1">
<title>Your Page title</title>
</head>
<body>
</body>
<SCRIPT LANGUAGE="JavaScript">
setTimeout("location.href ='<?php echo $redirect ?>'",500);
</script>
</html>
You can refer to oneclickmoviez.com and try to click any download link for my example.. try this : http://oneclickmoviez.com/dws/TURBOBIT/51776/7
I'm not too expert in php coding, so I hope you can show me 100% working codes.
For JavaScript timeout ins setTimeout is in miliseconds, so it should be 5000 for 5 seconds:
setTimeout ( expression, 5000 );
I would suggest use function expression, like this:
setTimeout ( function() {
/* code in here */
}, 5000 );
And least, use window.location like this
setTimeout ( function() {
window.location = '<?php echo $redirect ?>';
}, 5000 );
I'll recommend you to study little more about javascript.
I made a following sample which might meet your requirement, but you still need to know how this works to fit it in your project.
I'll recommend you to study following things to understand what I did -
Javascript setTimeout() - http://www.w3schools.com/js/js_timing.asp
Javascript getElementById() - http://www.tizag.com/javascriptT/javascript-getelementbyid.php
Javascript innerHTML - http://www.tizag.com/javascriptT/javascript-innerHTML.php
.
<?php
$redirect = $_SERVER['QUERY_STRING'].'';
?>
<html><head>
<meta name="robots" content="noindex" />
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Your Page title</title>
</head>
<body>
<div id="buttonArea">
</div>
</body>
<script type="text/javascript">
function loadButton()
{
button = document.getElementById('buttonArea');
button.innerHTML ='<button onclick="document.location=\'<?php echo $redirect ?>\'">Continue</button>';
}
setTimeout(loadButton(),5000);
</script>
</html>

php calling html

can you please let me know what I am missing:
<html>
<head><title>page</title></head>
<body>
<h2><center>Welcome to the mainpage</center></h2><br />
Home page
</body>
</html>
php code is :
<?PHP
$currpage=$_GET['currpage'];
echo "Hello world $currpage";
?>
when I click the homepage I want the sample4.php script to be executed and that output which is a html page to be displayed.
But when I click the homage page : I get a file window download.
I have the php script in the same location I have the html?
Does:
<html>
<head>
<title>My Page</title>
</head>
<body>
<p>Home page<p>
</body>
</html>
Do what you want? Otherwise, you'll need to show us the PHP code, in case it's making it a download from within the PHP.
For a hello world program, try this:
<html>
<head>
<title>My Page</title>
</head>
<body>
<?php
$currpage = isset($_REQUEST['currpage']) && is_int($_REQUEST['currpage'])?(int)$_REQUEST['currpage']:1;
echo "<p>Current page is $currpage</p>\n";
?>
</body>
</html>
You may also need to make sure that PHP is installed and running on your machine/server...
<html>
<head>
<title>My Page</title>
</head>
<body>
<?php
phpinfo();
?>
</body>
</html>

Categories