I have created a PHP password protected site with log-in page. I am using the following link for logging out.
<a href="admin.php?action=logout"?>Log out</a>
The problem is it redirects back to the index.php, but instead of showing my URL as EXAMPLE.com it shows my URL as EXAMPLE.com/index.php, which is undesirable. How can I accomplish a log-out and go back to the clean, desired url.
After logout redirect using the following command:
header("Location:http://www.example.com/login.php");
You can also do it by javascript in client side by using:
window.location='http://example.com/login.php'
In logout page you just add this redirect at the end of code
header("Location:http://www.example.com/");
This will redirect to the same index page with url example.com, but not show /index in url
Don't add
header("Location:http://www.example.com/index");
It will show example.com/index in url
Related
I have a website with Codeigniter 3 framework.
There is a login page as www.example.com/login
If author login to the panel they are redirecting to main page www.example.com/author/feed.
There are many pages in Author controller such as my-profile, edit-profile, reset-password etc.
If author wants to access www.example.com/author/my-profile they are redirected to www.example.com/login, after login they are redirected to to main page www.example.com/author/feed.
But I want them to redirect to www.example.com/author/my-profile.
What function I need to use in my code??
You can use the helper function redirect(). You can learn more here.
// after login
redirect('/author/my-profile');
You need to save your desired route in session before redirecting to login page like this:
$this->session->set_userdata('page', base_url('my-profile'));
When a user logs in, you can check if page is stored in session, otherwise redirect to base url:
$pageLink = base_url();
if ($this->session->userdata('page')) {
$pageLink = $this->session->userdata('page');
$this->session->unset_userdata('page');
}
redirect($pageLink);
have created a Facebook App,As we know Facebook app have 2 URLs. Page Tab URL and Application URL.In my code if I redirect user to Page Tab URL it gives me FacebookGraphMethod Exception.May be I need to redirect with additional parameters.Anyone who can help with this\
For Example
The Page Tab URL is abc.com/main.php
From main.php I navigate to xyz.php
Now I want to go back to main.php what should I do,I even tried window.location.href
Thanks
you first need to add your App to a page. Then, you can access it on this page by clicking he app icon (or to an URL like this: http://facebook.com/{{page_username}}/app_{{app_id}}).
You can get the page username using this method on FB API:
$profile = $facebook->api('/' . $PageInfo['page']['id'], 'GET');
$page_username = $profile['username'];
To add the app to a page, you can use the add page tab dialog: https://developers.facebook.com/docs/reference/dialogs/add_to_page/
Use top.location.href to redirect to page tab.
<?php
echo "<script type='text/javascript'>top.location.href='".$fbpagetaburl."';</script>";
exit;
?>
so here i am with "maybe another stupid question"
so here i want to ask how to redirect to previous page if the case is somehow like this:
i have view:
a. home_view b. about_view c. contact_view
then i have login view that (now currently after i login it'll redirect me into the home_view)
I want if i access login_view from about_view then the redirect function will redirect me to about_view, or if i access login_view from contact_view then the redirect function will redirect me to contact_view and so on. How to make redirect function to the previous page(not a single page) ? Maybe some tricks using php? or codeigniter itself?
It's simple when you have login and you go to login_view just set default redirect to about_view or contact_view when had login.
But if you want to redirect to previous page you have to trick with session must set session ex : $SESSION['last_view'] = $yourlastview;. $yourlastview can be set when you in about_view or contact_view or another view and when you go to login_view just check that $SESSION['last_view'] and redirect to that view.
Regard's
Jefri
You can use query string to solve this problem.
Like when you call login script from about us page access url as login.php?page=1 where page=1 for aboutus page similarly you can page=2 for contact us page. At login page you can get the redirect page by the query string can redirect to the respective after successfully login using header function.
e.g. Header('Location:about.php');
just use redirect($_SERVER['HTTP_REFERER'],'refresh')
This works.
$this->load->library('user_agent');
redirect($this->agent->referrer());
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 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
?>