It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a php page from where my users log-in to the application. It is working fine.
Yesterday, all of a sudden the users were able to login but were forced out and redirected to the login page again.
My database has logged in the user's login timings and this problem was automatically solved after about 2 hours.
Why will like this happen?
In the following code it will check for the session value and if it is not found then redirect to the error page.
Yesterday, it was redirecting to error page even if the session value was set.
<?php
if($_SESSION['ucd']<>"" && $_SESSION['sid']<>"" && $_SESSION['sid']<>0)
{
$query="select count(*) from active_sessions where user_cd='".$_SESSION['ucd']."'
and session_no='".$_SESSION['sid']."' and START_TM like DATE_FORMAT(now(),'%Y-%m-%d%')";
//echo $query;
$cnt=$dbop->select($query);
if($cnt[0] == '0')
{
$sender = "sender=".urlencode($_SERVER['PHP_SELF']);
session_unset();
header("Location:../login/error.html?$sender");
die;
}
else{
$query = "update active_sessions set LAST_ACTIVITY = NOW() WHERE SESSION_NO = ".$_SESSION['sid'];
mysql_query($query);
?>
<?php
}
}
else
{
$sender = "sender=".urlencode($_SERVER['PHP_SELF']);
session_unset();
header("Location:../login/error.html?$sender");
die;
}
?>
I don't see session_start() anywhere in your code.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have the following code:
public function get_facebook()
{
$loginUrl = Helpers::fbLogin();
if(Input::get('error'))
{
Session::flash('failure', 'You need to give permissions.');
return Redirect::to('signup');
}
else
{
$facebook = IoC::resolve('facebook-sdk');
$uid = $facebook->getUser();
$fbuser = $facebook->api('/me', 'GET');
$user = User::where('uid', '=', $uid)->or_where('email', '=', $fbuser['email'])->first();
if(is_null($user)){
Session::flash('fbuser', $fbuser);
return Redirect::to('signup');
} else {
Auth::login($user);
return Redirect::to('/');
}
}
return Redirect::to($loginUrl);
}
But I get this message:
An active access token must be used to query information about the current user.
Also when I print the $facebook->getAccessToken() & try opening my app with different facebook accounts I get same token.
What is access token & what do we use it for?
P.S. I have set up properly my appID & secret code. The problem is that sometimes it works, sometimes it doesn't.
Access token is token, that is given to your application by user to access his/her information from your application. In order to get that token, user has to give you permission to access at least his basic information.
More here
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a page count to limit the number of times a logged out user can view profiles. If a user is logged out they are redirected to a sign-up page, this is right and should be what's happening but i'm getting the same thing happen when the user is logged in, how can i add an else statement or if statement to say only redirect to sign up page or only limit profile hits if not logged in?
Thanks
<?
!session_id() ? session_start() : null;
verify_profile_visit_limit();
function verify_profile_visit_limit(){
$free_profiles = array(99999,99998,99997,99996,99995,99994,99993);
if(in_array($_GET["id"], $free_profiles)) return;
if(! isset($_SESSION["page_access_count"])){
$_SESSION["page_access_count"] = 1;
}
$_SESSION["page_access_count"]++;
if($_SESSION["page_access_count"] > 5){
header("Location: limit.php");
exit();
}
}
?>
Just add an OR condition so you return if the user is logged in:
if(in_array($_GET["id"], $free_profiles) || isset($_SESSION['loggedIn']) && $_SESSION['loggedIn']) return;
With that your function will return before running the limit check. Assuming you store a boolean (true/false) in $_SESSION['loggedIn'].
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
My pseudo code is as follows:
if($_GET['action'] == 'list'){
do function getFileList($dir)
else
do nothing
exit;
}
require_once "./dir.php";
require_once "./echo.php";
function getFileList($dir)
{
}
Your psuedo code is almost there.
require_once "./dir.php";
require_once "./echo.php";
function getFileList($dir)
{
/* ... */
}
if($_GET['action'] == 'list') {
getFileList($dir);
}
Are you asking how to send a variable via GET to a PHP file from within the same PHP file? You can create a form that submits to itself: http://www.tellingmachine.com/post/Simple-self-submitting-PHP-forms.aspx.
If you are looking to do something else, please provide additional details.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
...the conditions of an if statement are fulfilled?
I have some code to add data to a database if certain conditions are met, after the data is added I want the page to redirect to another page? How can I do this?
Use if-else condition. You can use header() of PHP .
if(/* Your conditions */){
// redirect if fulfilled
header("Location:nxtpage.php");
}else{
//some another operation you want
}
You shoul use header php function
<?php
//some conditions
header("Location: http://www.example.com/");
?>
try this code
$query ="insert into test values (1,'test')";
if(mysql_query($query) == true)
{
header('location:index.php');
exit();
}
else
{
echo " insert failed";
}
Try PHP Header:
header('Location: http://www.example.com/');
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I found a great contact form over here. How to show a "Successfully sent" message right under the contact from instead of using a redirect to an other page?
$formproc->SetFormRandomKey('9nLzAt2cQM2Zysm');
if(isset($_POST['submitted']))
{
if($formproc->ProcessForm())
{
$formproc->RedirectToURL("thank-you.php");
}
}
Change the form process code to this.
$formproc->SetFormRandomKey('9nLzAt2cQM2Zysm');
$successful = false;
if(isset($_POST['submitted']))
{
if($formproc->ProcessForm())
{
$successful = true;
}
}
Where you want the message to show.
if($successful){
echo "Successfully sent.";
}