Adding an else statement to page count? [closed] - php

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'].

Related

Custom error message for input [closed]

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 9 years ago.
I'm trying to set a custom message for an input:
$this->form_validation->set_message('username', 'Choose a business, Mang!');
and display this:
<?php echo form_error('username'); ?>
But nothing displays for me, what is wrong?
Is this what I need? Example:
if($result)
{
$this->form_validation->set_message('username', 'Choose a business, Mang!');
}
You need to set rules as such:
$this->form_validation->set_rules('form_field_username', 'username', 'required|callback_business_check');
function business_check($username) {
if(strlen($this->input->post('form_field_business')) == 0) {
$this->form_validation->set_message('business_check', 'Choose a business, Mang!');
return false;
}
return true;
}
This is providing I have the right idea of what you are doing...

How can I use $_GET in the same page [closed]

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.

How can I use PHP to automatically change the page if [closed]

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/');

PHP - Contact form sent message [closed]

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.";
}

Automatic logged out [closed]

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.

Categories