Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7873119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:25:08+00:00 2026-06-03T02:25:08+00:00

I would like to dedicate this page to handling sessions using procedural php. I’ll

  • 0

I would like to dedicate this page to handling sessions using procedural php.

I’ll begin with how I start most of my projects:

session_name('Easy_App');
session_start();

if (!isset( $_SESSION['ip'] )){
    $_SESSION['ip'] = $_SERVER['REMOTE_ADDR'];
}

if (!isset( $_SESSION['created'] )){
    $_SESSION['created'] = time();
}

if (!isset( $_SESSION['overall_views'] )){
    $_SESSION['overall_views'] = 1;
}
else {
    $_SESSION['overall_views']++;
}

if (!isset( $_SESSION['username'] )){
    $_SESSION['username'] = "";
}

if (!isset( $_SESSION['logged_in'] )){
    $_SESSION['logged_in'] = 0;
}

/*A quick method to keep pageviews to < 5 pages per 1 second per session*/
if (!isset($_SESSION['first_action'])){
   $_SESSION['first_action'] = time();
}

$first_action = $_SESSION['first_action'];
if (!isset( $_SESSION['action'] )){
   $_SESSION['action'] = 1;
}
else{
  $_SESSION['action']++;
}

$action=$_SESSION['action'];
if ($action>=5){
  unset($_SESSION['action']);
  unset($_SESSION['first_action']);
  if((time() - $first_action) <=1){
    exit("Please Don't Hammer My Site ");
  }
}

So We have a starting point:

  1. The Start of a session with a few regularly used parameters
  2. In the last few lines, prevention of hammering by casual users.

My question is this:

Where would you go from here? Improvements of the above code or a brief snippet of how you handle sessions using procedural php would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:25:10+00:00Added an answer on June 3, 2026 at 2:25 am

    Your code would not work If you are trying to STOP Hammer or FLOODING if the user doesn’t keep cookies your Sessions are useless and the script is a waste … you should try better approach using storage systems like memcache , mongoDB or redis

    See : https://stackoverflow.com/a/10155437/1226894 …. this has been answered before

    EDIT 1

    Am not sure what you want by procedural PHP but i hope this helps

    Objectives

    • Remove duplicate isset
    • Remove duplicate if Statement
    • Create single function to get and set $_SESSION
    • Trying to make everything a function and hide all variables

    Final Code

    session_start ();
    include("procedural.function.php");
    __SESSION ( 'ip', $_SERVER ['REMOTE_ADDR'] );
    __SESSION ( 'created', time () );
    __SESSION ( 'overall_views', 1 );
    __SESSION ( 'overall_views', "++" );
    __SESSION ( 'username', "" );
    __SESSION ( 'logged_in', 0 );
    __SESSION ( 'first_action', time () );
    __SESSION ( 'action', "++" );
    
    if (__SESSION ( 'action' ) >= 5) {
        __UNSET ( 'action' );
        __UNSET ( 'first_action' );
        if ((time () - __SESSION ( 'first_action' )) <= 1) {
            exit ( "Please Don't Hammer My Site " );
        }
    }
    

    procedural.function.php

    function __SESSION($var, $value = null) {
        if ($value === null) {
            return isset ( $_SESSION [$var] ) ? $_SESSION [$var] : null;
        } else if ($value === "++") {
            isset ( $_SESSION [$var] ) ? $_SESSION [$var] ++ : $_SESSION [$var] = 0;
            return $_SESSION [$var];
        } else {
            isset ( $_SESSION [$var] ) ? $_SESSION [$var] = $value : null;
            return $value;
        }
    }
    
    
    function __UNSET($var) {
        unset ( $_SESSION [$var] );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to connect to a clustered Oracle database described by this TNS:
I would like to know what guys are using to make diagram of your
I would like this: <NOSCRIPT> <META HTTP-EQUIV=refresh CONTENT=1; URL=js/nonJs.htm> </NOSCRIPT> to be the first
What I would like to do is retrieve the contents of a PHP file
I would like run a PHP script that runs every second to update a
I would like to start a cluster node on a dedicated server. However When
I would like to run ffmpeg from PHP for video encoding purposes. I was
I'm using MongoDB, and I would like to generate unique and cryptical IDs for
As the title suggests, I would like to see if this is something people
I know this question has been asked several times, but I would like to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.