Author Topic: [TWEAK] - Universal cookie integration in 4images (includes/sessions.php file)  (Read 27444 times)

0 Members and 1 Guest are viewing this topic.

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Hi, in forum - is BIG search for how integrate cookie of other MOD (forum) for ALL cookie prefix in includes/sessions.php file. Now - search finish. :twisted:
Tweak check for sequential cookie name you add in array. ;)

In includes/sessions.php file,

find:

Code: [Select]
//-----------------------------------------------------
//--- Start Session -----------------------------------
//-----------------------------------------------------
define('COOKIE_NAME', '4images_');
define('COOKIE_PATH', '');
define('COOKIE_DOMAIN', '');
define('COOKIE_SECURE', '0');

replace:

Code: [Select]
//-----------------------------------------------------
//--- Start Session -----------------------------------
//-----------------------------------------------------
//define('COOKIE_NAME', '4images_');
//define('COOKIE_PATH', '');
//define('COOKIE_DOMAIN', '');
//define('COOKIE_SECURE', '0');

$cookie_name = array("4images_");
$cookie_path = array("");
$cookie_domain = array("");
$cookie_secure = array("0");

Find:

Code: [Select]
function set_cookie_data($name, $value, $permanent = 1) {
      global $HTTP_COOKIE_VARS;
    $cookie_expire = ($permanent) ? $this->current_time + 60 * 60 * 24 * 365 : 0;
    $cookie_name = COOKIE_NAME.$name;
    setcookie($cookie_name, $value, $cookie_expire, COOKIE_PATH, COOKIE_DOMAIN, COOKIE_SECURE);
    $HTTP_COOKIE_VARS[$cookie_name] = $value;
  }

replace:

Code: [Select]
function set_cookie_data($name, $value, $permanent = 1) {
      global $HTTP_COOKIE_VARS, $cookie_name, $cookie_path, $cookie_domain, $cookie_secure;     
     
      if (isset($cookie_name) && is_array($cookie_name) && !empty($cookie_name)) {
          $cookie_name_array = array();
          foreach ($cookie_name as $key => $val) {
              $cookie_name_array[] = $val;
          }
      }
     
      if (isset($cookie_path) && is_array($cookie_path)) {
          $cookie_path_array = array();
          foreach ($cookie_path as $key => $val) {
              $cookie_path_array[] = $val;
          }
      }

      if (isset($cookie_domain) && is_array($cookie_domain)) {
          $cookie_domain_array = array();
          foreach ($cookie_domain as $key => $val) {
              $cookie_domain_array[] = $val;
          }
      }
     
      if (isset($cookie_secure) && is_array($cookie_secure) && !empty($cookie_name)) {
          $cookie_secure_array = array();
          foreach ($cookie_secure as $key => $val) {
              $cookie_secure_array[] = $val;
          }
      }
     
      $num_cookie_name = (isset($cookie_name_array)) ? sizeof($cookie_name_array) : "";
      $num_cookie_path = (isset($cookie_path_array)) ? sizeof($cookie_path_array) : "";
      $num_cookie_domain = (isset($cookie_domain_array)) ? sizeof($cookie_domain_array) : "";
      $num_cookie_secure = (isset($cookie_secure_array)) ? sizeof($cookie_secure_array) : "";

      $cookie_expire = ($permanent) ? $this->current_time + 60 * 60 * 24 * 365 : 0;
     
      for ($i = 0; $i < $num_cookie_name; $i++) {   
          $each_cookie_name = $cookie_name_array[$i] . $name;
          for ($j = 0; $j < $num_cookie_path; $j++) {       
              $each_cookie_path = $cookie_path_array[$i];
              for ($k = 0; $k < $num_cookie_domain; $k++) {           
                  $each_cookie_domain = $cookie_domain_array[$i];
                  for ($l = 0; $l < $num_cookie_secure; $l++) {
                      $each_cookie_secure = $cookie_secure_array[$i];
                      setcookie($each_cookie_name, $value, $cookie_expire, $each_cookie_path, $each_cookie_domain, $each_cookie_secure);
                      $HTTP_COOKIE_VARS[$each_cookie_name] = $value;
                      break;
                  }
                  break;
              }       
              break;       
          }
      }
      unset ($cookie_secure_array);
      unset ($cookie_domain_array);
      unset ($cookie_path_array);
      unset ($cookie_name_array);
  }

find:

Code: [Select]
function read_cookie_data($name) {
    global $HTTP_COOKIE_VARS;
    $cookie_name = COOKIE_NAME.$name;
    return (isset($HTTP_COOKIE_VARS[$cookie_name])) ? $HTTP_COOKIE_VARS[$cookie_name] : false;
  }

replace:

Code: [Select]
function read_cookie_data($name) {     
    global $HTTP_COOKIE_VARS, $cookie_name;
   
    if (isset($cookie_name) && is_array($cookie_name) && !empty($cookie_name)) {
        foreach ($cookie_name as $key => $val) {
            $each_cookie_name = $val . $name;
            return (isset($HTTP_COOKIE_VARS[$each_cookie_name])) ? $HTTP_COOKIE_VARS[$each_cookie_name] : false;
        }
    }
  }

// How:

Ok, e.g (NO REAL PREFIX :!: - is e.g) - for phpbb.

Quote
$cookie_name = array("4images_", "phpbb_");
$cookie_path = array("", "path_phpbb");
$cookie_domain = array("", "domain_phpbb");
$cookie_secure = array("0", "cookie_secure_value_phpbb"); // (1 for phpbb - e.g).

Note: Cookie name is must same name prefix for real phpbb.

Now - is easy for add table prefix in config and includes/constants.php + SQL table in includes/sessions.php file for check session. ;)
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline Mr_LovaLove

  • Full Member
  • ***
  • Posts: 233
  • Unkown
    • View Profile
Damin ! what a nice tweak

sound greats

i will do it 2day and tell u the result :)

thanks man

u r da best
English Please :@

Offline Mr_LovaLove

  • Full Member
  • ***
  • Posts: 233
  • Unkown
    • View Profile
well, thanks for this ! 

but it seems big jump or somethin for pro php coder not for newbie like me :P

well,

i did all these steps !

but i faced some errors

infact, im trying to integrate 4images with vb ( in one database )

so that mean

in 4images need to change :

1- admin_global
2- constans
3-sessions
4-page_header

so do i have to put all changes and add ur tweak in session


and this is part of the session that  i use in the 4images ( from the intgrate mod )

Code: [Select]
//-----------------------------------------------------
//--- Start Session -----------------------------------
//-----------------------------------------------------
$optionstemp = $site_db->query_firstrow("SELECT template FROM ".VB_TEMPLATE_TABLE." WHERE title='options'");
eval($optionstemp['template']);

define('COOKIE_NAME', '');
define('COOKIE_PATH', $cookiedomain);
define('COOKIE_DOMAIN', $cookiepath);
$secure = (isset($SERVER_PORT) && $SERVER_PORT == "443") ? 1 : 0;
define('COOKIE_SECURE', $secure);

//Start Session
$site_sess = new Session();

or

use the real session from 4images

or

im dreaming and this tweak talks about something else




English Please :@

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
I post e.g on 1st post ...

this is cookie session for integrate ... all other ... if need for integrate - is no change for add in PHP file ...
Universal Cookie Integration Tweak is for assign new cookie for each script integrate in session and check for match session. ;)
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline Mr_LovaLove

  • Full Member
  • ***
  • Posts: 233
  • Unkown
    • View Profile
i add something in my last post ^_^

okay ,

but  the code that u say to be changed is not in the session i use in 4image coz i changed the session file

also change the constans and page_header plus the admin_global
English Please :@

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
What is $cookiedomain and $cookiepath and $secure from ? What is cookie name prefix for vBulletin ?
For admin_global, constants and page_header, is no different in vBulletin instruction. ;)
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline Mr_LovaLove

  • Full Member
  • ***
  • Posts: 233
  • Unkown
    • View Profile
Code: [Select]
define('SESSION_NAME', 's'); // Default of vBulletin is "s".
define('COOKIE_PREFIX', 'bb'); //Default of vBulletin is "bb".
define('COOKIE_TIMEOUT','1800'); //Set the same with your vB timeout, in second
define('ALBUM_FOLDER','/image/'); //Your Album Folder WITH trailing slash

this code and the old code

are both in session.php
English Please :@

Offline thunderstrike

  • 4images Guru
  • *******
  • Posts: 2.327
    • View Profile
Code: [Select]
define('SESSION_NAME', 's'); // Default of vBulletin is "s".
define('COOKIE_PREFIX', 'bb'); //Default of vBulletin is "bb".
define('COOKIE_TIMEOUT','1800'); //Set the same with your vB timeout, in second
define('ALBUM_FOLDER','/image/'); //Your Album Folder WITH trailing slash

this code and the old code

are both in session.php

Ok and ... for this ?

What is $cookiedomain and $cookiepath and $secure from ? What is cookie name prefix for vBulletin ?
For admin_global, constants and page_header, is no different in vBulletin instruction. ;)
8 steps need when ask question -

- PHP version (ACP - > phpinfo())
- mySQL version (ACP - > phpinfo())
- 4images version
- Post screenshot / URL
- Post code in BB Code (no need full file for code) or post attach file
- It doesn't work. What is say - what is do for no work
- Install MOD ? If so - please say (troubleshooting)
- Read FAQ ? Install Bug fixes ?

Offline Mr Kennedy

  • Jr. Member
  • **
  • Posts: 81
    • View Profile
I have 1.7.4 and did what in the first post is written...
but wenn i'm on new images i got these errors:


Notice: Use of undefined constant COOKIE_PATH - assumed 'COOKIE_PATH' in /usr/export/www/vhosts/funnetwork/hosting/strangebuttrue/4images/includes/page_header.php on line 645

Notice: Use of undefined constant COOKIE_DOMAIN - assumed 'COOKIE_DOMAIN' in /usr/export/www/vhosts/funnetwork/hosting/strangebuttrue/4images/includes/page_header.php on line 645

Notice: Use of undefined constant COOKIE_SECURE - assumed 'COOKIE_SECURE' in /usr/export/www/vhosts/funnetwork/hosting/strangebuttrue/4images/includes/page_header.php on line 645

Notice: Use of undefined constant COOKIE_PATH - assumed 'COOKIE_PATH' in /usr/export/www/vhosts/funnetwork/hosting/strangebuttrue/4images/includes/page_header.php on line 659

Notice: Use of undefined constant COOKIE_DOMAIN - assumed 'COOKIE_DOMAIN' in /usr/export/www/vhosts/funnetwork/hosting/strangebuttrue/4images/includes/page_header.php on line 659

Notice: Use of undefined constant COOKIE_SECURE - assumed 'COOKIE_SECURE' in /usr/export/www/vhosts/funnetwork/hosting/strangebuttrue/4images/includes/page_header.php on line 659