I have built a webpage, splashcreen.html, that when someone loads index.php will automatically go to. But I wish to also have a button, return to index.php, that allows users to go back to the homepage. But if the person closes the browser, this entire process restarts.
So it goes:
Open browser, index.php
Redirect to splashcreen.html
user clicks button, return to index.php
navigate without redirect
User closes browser
reopen and start this whole process again.
Is this possible?
Thanks!
Save a cookie, or send a GET value:
Go Home!.
You could have your index.php as the splash screen. Then the user clicks the button, redirect to home.php which is the "real" homepage.
Then instead of Home links pointing to the root (which implies index.php, therefore splash screen), have them point to home.php instead.
So:
user opens yoursite.com and meets your splash screen
user clicks button to go to home.php
user navigates normally
once user closes and reopens browser to visit yoursite.com, well.. splash screen again!
If later on you get tired of the splash screen and plan not to use it anymore, you can use a simple .htaccess rule to redirect index.php requests to home.php
Yes, just set a cookie with JavaScript when the button is clicked in splashscreen.html, and have the php (or JS, whatever's redirecting) on index.php not rediect if the cookie is set. This is pretty easy, just search for it on Google.
You dont actually need to redirect to splash.html you could just use a session to store if its been seen or just continue to do your index.php
index.php
<?php
session_start();
if(!isset($_SESSION['splash'])){
//Show splash screen
ob_start();
include('./splash.html');
$contents = ob_get_contents();
ob_end_clean();
echo $contents;
$_SESSION['splash']=true;
die;
}
//Do normal index.php
?>
Related
How can I make "location.reload()" on php file without get perimeter ?
Here is an example..
Let's say I have PHP, and at the right top, I have logout button.
When user press that button, PHP will automatically re-direct to "index.php?logout" and after that, i will logout (unset cookie and other) and return ( javascript location.reload() ) to main page (login page)
Problem that I have is, when php return to login page after logout, then url is still "index.php?logout", so when user login back with "index.php?logout" page, it will automatically logout (because of ?logout perimeter on url)..
So how can I tackle this problem ? Anybody got any idea ?
I hope you all understand what i'm trying to tell you all about..
Thanks for reading this..
use self.location.reload instead of location.reload. Because location.reload reloads the current page. You can simple use
self.location.reload = index.php
Or you can remove query paramter from your url like
var url = 'index.php?logout'
url=url.split("?")[0];
location.reload =url
location.reload() reloads the current page with the post data,you should use window.location.href in case of login/logout
When user press that button, PHP will automatically re-direct to "index.php?logout" and >after that, i will logout (unset cookie and other) and return ( javascript location.reload() >) to main page (login page)
all these can be implemented in server side.
// LOGOUT
if(isset($_GET['logout'])){
//logout code
}
header('location: www.yoursite.com/login') //or whatever the url is
exit;
you re-direct to login page and save page url that request for login that is index.php?logout for re-direct back you must check perimeter logout if exist remove it from return url for example
//replace parent::$Patch with your root url like "http://localhost/myapp/"
if(!parent::$Patch.'admin/login.php'=='http://'.$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']){//check if you are in login.php page didn't redirect to login.php
if(!#header('Location:'.parent::$Patch.'admin/login.php?url='.rawurlencode(str_replace("logout","",'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'])))){
//if header error echo javaScript code for re-direct
?>
<!DOCTYPE HTML>
<html>
<head>
<script language="javascript">
var LoadP = <?php print "'".parent::$Patch.'admin/login.php?url='.rawurlencode(str_replace("logout","",'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']))."'"?>;
self.location = LoadP;
</script></head></html>
<?php
}
exit();
}
}
this code re-direct user to login page and keep return url of page. if logout exist inside of return url remove it
i hope it can help you
I was wondering if anyone know how to achieve this.
I have an index.php that loads a file page.php into a div using jQuery. This page.php has a link that when you click it loads page2.php into the same div(so the url always stays as index.php).
I want to make it so that, if you open the link on page.php in a new tab or window, instead of loading page2.php, it loads index.php(with page.php in the div). Same if you type in the link to page2.php directly into the browser.
Use a session.
On page 1:
session_start();
$_SESSION['beenhere'] = 1;
on page 2
session_start();
if(!isset($_SESSION['beenhere'])){
header('./index.php');
}
//rest of page....
This is for the 'open in new tab' part
index.php
Link
<div id="myDiv"></div>
To make it work also if the user writes the direct link to the page just check in page2 if it has a referer and if doesn't just send him to index.php
page2.php
if ($_SERVER['HTTP_REFERER']!="index.php"){
header("Location: http://www.example.com/index.php");
}
set a global variable on index.php and if it isn't there when page.php is loaded, redirect to index.php.
I'm working on a jquery mobile web app and do a sessioncheck with php on pages I need the user to be logged-in. If not, the user will be redirected to the login.php?r=L29yZGVyLnBocD9kZWFsX2lkPTEwMDM2MjM= (base64_encode($_SERVER['REQUEST_URI']) to login. After the login he has to be redirected to the page he actually requested.
Unfortunately JQM doesn't update the URL, so i can't grab the GET parameter ?r=.... as it is not there. Just a page reload (F5) updates the url.
Here the sessioncheck code which does the redirect if user is not logged-in:
if(!isset($_SESSION["member"]) || (isset($_SESSION["member"]) && (int)$_SESSION["member"]["member_id"]==0)){
unset($_SESSION["member"]);
Header("Location: " . SITE_ROOT . "/login.php?r=".base64_encode($_SERVER['REQUEST_URI']));
exit;
}
What do you guys suggest to tell jQuery mobile that the target has changed.
Of course my redirect happens before the DOCTYPE tag
Cheers
Did you specify a data-url attribute into the page div?
<div data-role="page" data-url="/login" id="login-page">
I am working with api in php/ajax and i have in every page included test if a user hasnt been logged out because of inactivity after a certain time. It works but in some moments i have troubles. Here's the story:
I have one file called index.php. Index.php has a div - let's name it 'div'. It also has some buttons - let's name it "new" and "modify". When i press a button, body of file new.php and modify.php is loaded via ajax method to 'div'. So far so good. But when user becomes inactive for certain time it should logout him. And it does. But unfortunatelly - and it's clear why it is happening - logout page is not printed into index.php, but to the body of "div". It's easy to understand - pressing "new" button moves me to new.php. New.php checks if i am logged in - i am not so it redirects me to logout.page so new.php is resulting logout page and it becomes a body of my "div". Here's the question: how to redirect whole page (index.php) to logout page if i am logged out and not print it in div.
Remember that pressing "new" button doesnt refresh index.php becuase i use ajax. It only refreshes my div. Is it even possible?
Don't do your redirect in new.php, instead make that PHP script return some particular value when the user is logged out, analyze that output in your AJAX call and do the redirect via javascript if necessary.
In other words:
if new.php succeeds do what you normally do
if new.php returns some "authentication failure" status, do your redirect
The best way is to encapsulate AJAX responses in a JSON object so you can have both data and response codes for easier analizing on the javascript side.
How about using javascript redirect ? You really do not need to care about "hacker" users, because they will not have any permissions without logging in, so just redirect normal users with:
<script language="JavaScript">document.location="/logout.php";</script>
Try this - change "3000" to any number of miliseconds (e.g. if it's 15 minutes, set it to "900000")
<script>
(function(){
setTimeout( function(){
window.location = "www.yourawesomesite.com/logout";
}
,3000)
})();
</script>
I wanted to popup an alert box. After that, the site would redirect to main page. But, it seems that it directly redirect to the mainpage without alerting anything.
if($registerquery)
{
?>
<script>alert('received!')</script>
<?php
}
header("Location: mainpage.php");
exit();
?>
I wanted to do this to ensure users that the process of submission ended successfully. How can i alert something before the page redirect to mainpage and more importantly what causes this? I think the page should not have redirected before the alert box.(Before these codes, site registers what users submitted but not relevant i guess.)Thanks
You just can't do this. PHP is server-side, JS is client-side. Using a location header is server-side, so the browser never gets the JS.
Instead, try something more like:
if( $registerquery)
echo "<script>alert('received!'); location.href='mainpage.php';</script>";
and remove the header bit altogether.