Codeigniter session in sub directory - codeigniter

I am using CI version 3 with session driver as files. I just want to get session variables in some sub directory but print_r($_SESSION) not printing my saved session variables.
Can some one help how do i get session in sub-directory.
In addition, I have tried below and getting some variable checking set or not but don't know how to get all variables value from saved session files that I am saving in my tmp folder at root
if(isset($_COOKIE['ci_session'])) {
$file = '../tmp/ci_session'.$_COOKIE['ci_session'];
if(file_exists($file)){
$handle = fopen($file, "r");
$contents = fread($handle, filesize($file));
//echo $contents;
$pos = strpos($contents, 'logged_in');
if ($pos === false) {
echo "Logged out";
} else {
echo "Logged in";
}
fclose($handle);
}
}

Change your config.php file configuration where you want to get your all session data
$config['sess_save_path'] = APPPATH.'test';
Above config will store all sessions in application/test directory

Related

Laravel Collective SSH results

I am performing SSH in Laravel whereby I connect to another server and download a file. I am using Laravel Collective https://laravelcollective.com/docs/5.4/ssh
So, the suggested way to do this is something like this
$result = \SSH::into('scripts')->get('/srv/somelocation/'.$fileName, $path);
if($result) {
return $path;
} else {
return 401;
}
Now that successfully downloads the file and moves it to my local server. However, I am always returned 401 because $result seems to be Null.
I cant find much or getting the result back from the SSH. I have also tried
$result = \SSH::into('scripts')->get('/srv/somelocation/'.$fileName, $path, function($line){
dd( $line.PHP_EOL);
});
But that never gets into the inner function.
Is there any way I can get the result back from the SSH? I just want to handle it properly if there is an error.
Thanks
Rather than rely on $result to give you true / false / error, you can check if the file was downloaded successfully in another way:
// download the file
$result = \SSH::into('scripts')->get('/srv/somelocation/'.$fileName, $path);
// see if downloaded file exists
if ( file_exists($path) ) {
return $path;
} else {
return 401;
}
u need to pass file name also like this in get and put method:
$fileName = "example.txt";
$get = \SSH::into('scripts')->get('/remote/somelocation/'.$fileName, base_path($fileName));
in set method
$set = \SSH::into('scripts')->set(base_path($fileName),'/remote/location/'.$fileName);
in list
$command = SSH::into('scripts')->run(['ls -lsa'],function($output) {
dd($output);
});

Error index.php not writeable Administrator index.php not writeable In opencart

i've got problem when i install vqmod in opencart the error say
index.php not writeable
Administrator index.php not writeable
i have no index.php file in my root opencart ,
Admin/index.php
<?php
// Version
define('VERSION', '2.3.0.2');
// Configuration
if (is_file('config.php')) {
require_once('config.php');
}
// Install
if (!defined('DIR_APPLICATION')) {
header('Location: ../install/index.php');
exit;
}
// Startup
require_once(DIR_SYSTEM . 'startup.php');
start('admin');
vqmod/install/index.php
// CHANGE THIS IF YOU EDIT YOUR ADMIN FOLDER NAME
$admin = 'admin';
// Counters
$changes = 0;
$writes = 0;
// Load class required for installation
require('ugrsr.class.php');
// Get directory two above installation directory
$opencart_path = realpath(dirname(__FILE__) . '/../../') . '/';
// Verify path is correct
if(!$opencart_path) die('COULD NOT DETERMINE CORRECT FILE PATH');
$write_errors = array();
if(!is_writeable($opencart_path . 'index.php')) {
$write_errors[] = 'index.php not writeable';
}
if(!is_writeable($opencart_path . $admin . '/index.php')) {
$write_errors[] = 'Administrator index.php not writeable';
}
if(!empty($write_errors)) {
die(implode('<br />', $write_errors));
}
// Create new UGRSR class
$u = new UGRSR($opencart_path);
// remove the # before this to enable debugging info
#$u->debug = true;
// Set file searching to off
$u->file_search = false;
// Attempt upgrade if necessary. Otherwise just continue with normal install
$u->addFile('index.php');
$u->addFile($admin . '/index.php');
$u->addPattern('~\$vqmod->~', 'VQMod::');
$u->addPattern('~\$vqmod = new VQMod\(\);~', 'VQMod::bootup();');
$result = $u->run();
if($result['writes'] > 0) {
if(file_exists('../mods.cache')) {
unlink('../mods.cache');
}
die('UPGRADE COMPLETE');
}
$u->clearPatterns();
$u->resetFileList();
// Add catalog index files to files to include
$u->addFile('index.php');
// Pattern to add vqmod include
$u->addPattern('~// Startup~', '// VirtualQMOD
require_once(\'./vqmod/vqmod.php\');
VQMod::bootup();
// VQMODDED Startup');
$result = $u->run();
$writes += $result['writes'];
$changes += $result['changes'];
$u->clearPatterns();
$u->resetFileList();
// Add Admin index file
$u->addFile($admin . '/index.php');
// Pattern to add vqmod include
$u->addPattern('~// Startup~', '//VirtualQMOD
require_once(\'../vqmod/vqmod.php\');
VQMod::bootup();
// VQMODDED Startup');
$result = $u->run();
$writes += $result['writes'];
$changes += $result['changes'];
$u->addFile('index.php');
// Pattern to run required files through vqmod
$u->addPattern('/require_once\(DIR_SYSTEM \. \'([^\']+)\'\);/', 'require_once(VQMod::modCheck(DIR_SYSTEM . \'$1\'));');
// Get number of changes during run
$result = $u->run();
$writes += $result['writes'];
$changes += $result['changes'];
// output result to user
if(!$changes) die('VQMOD ALREADY INSTALLED!');
if($writes != 4) die('ONE OR MORE FILES COULD NOT BE WRITTEN');
die('VQMOD HAS BEEN INSTALLED ON YOUR SYSTEM!');
you need to do two things
1)open vqmod/install/index.php
find the following code
$admin = 'admin';
change its value to your admin folder name that you have changed to
$admin = 'youradminfoldername';
2)open vqmod/pathReplaces.php
find the following code (if there is no,add it)
$replaces[] = array('~^admin\b~', 'xxxxx');
change xxxxx to your current admin folder name.
after you have these two things,even if it still show such infomation,
you should be ok to install extension.
I have tested this method ,it works for me.
another solution I guess maybe is to delete vqmod folder and reupload vqmod-opencart-2.6.1,and then only need to modify vqmod/pathReplaces.php,it should works
It probably means that you've deleted the file. You might have to reinstall the Opencart or upload the file from default opencart source files.
Open cPanel File Manager Set permission to 777 for the file

Migrating Parse files from Gridstore to S3

We migrated the data(without files) to mLab and Heroku. So the old files are still on Parse.
Since then, any new file added goes into Gridstore, which is the default file storage for mLab.
Now I migrated old parse files from Parse to an S3 Bucket using sashido
The files are migrated and are accessible using S3Adapter in Heroku.
But the files on Gridstore are not accessible now. How can I migrate them to the same S3 bucket and change references in mLab?
Maybe you're interested in the solution I've tried. It's not a simple operation, but I migrated successfully 3 databases with my parse server configuration.
It's based in a PHP script (with the Parse PHP SDK) that runs through every object, it gets the file from Parse.com and sets it (with any of your adapter configuration) in your own server.
The script looks like:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
date_default_timezone_set('America/New_York');
$fileField = $argv[1];
$class = $argv[2];
require_once 'vendor/autoload.php';
use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseACL;
use Parse\ParsePush;
use Parse\ParseUser;
use Parse\ParseInstallation;
use Parse\ParseException;
use Parse\ParseAnalytics;
use Parse\ParseFile;
use Parse\ParseCloud;
use Parse\ParseClient;
$app_id = "******";
$rest_key = "******";
$master_key = "******";
ParseClient::initialize($app_id, $rest_key, $master_key);
ParseClient::setServerURL('http://localhost:1338/', 'parse');
$query = new ParseQuery($class);
$query->ascending("createdAt"); // it's just my preference
$query->exists($fileField);
$query->limit(1);
$count = $query->count();
for ($i = 0; $i < $count; $i = $i + 1) {
try {
$query->skip($i);
// get Entry
$entryWithFile = $query->first();
// get file
$parseFile = $entryWithFile->get($fileField);
// filename
$fileName = $parseFile->getName();
// if the file is hosted in Parse, do the job, otherwise continue with the next one
if (strpos($fileName, "tfss-") === false) {
echo "\nThis is already an internal file, skipping...";
continue;
}
$newFileName = str_replace("tfss-", "", $fileName);
$binaryFile = file_get_contents($parseFile->getURL());
$newFile = ParseFile::createFromData($binaryFile, $newFileName);
$entryWithFile->set($fileField, $newFile);
$entryWithFile->save(true);
echo "\nFile saved\n";
}
catch (Exception $e) {
// The conection with mongo or the server could be off for some second, let's retry it ;)
sleep(10);
continue;
}
}
echo "\n";
echo "END!";
?>
set your parse url correctly.
Imagine you want to migrate the file from class _User with field imageProfile, so be sure that you pass $fileField = "imageProfile"; $class = "_User".
Run that code for any field per class.
I did a dumb solution to work in parallel, which would be skipping steps in the for loop, for example:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
date_default_timezone_set('America/New_York');
$index = $argv[1];
$of = $argv[2];
$fileField = $argv[3];
$class = $argv[4];
require_once 'vendor/autoload.php';
use Parse\ParseObject;
use Parse\ParseQuery;
use Parse\ParseACL;
use Parse\ParsePush;
use Parse\ParseUser;
use Parse\ParseInstallation;
use Parse\ParseException;
use Parse\ParseAnalytics;
use Parse\ParseFile;
use Parse\ParseCloud;
use Parse\ParseClient;
$app_id = "********";
$rest_key = "********";
$master_key = "********";
ParseClient::initialize($app_id, $rest_key, $master_key);
ParseClient::setServerURL('http://localhost:1338/', 'parse');
$query = new ParseQuery($class);
$query->ascending("createdAt");
$query->exists($fileField);
$query->limit(1);
$count = $query->count();
for ($i = $index; $i < $count; $i = $i + $of) {
try {
$query->skip($i);
// get Entry
$entryWithFile = $query->first();
// get file
$parseFile = $entryWithFile->get($fileField);
// filename
$fileName = $parseFile->getName();
// if the file is hosted in Parse, do the job, otherwise continue with the next one
if (strpos($fileName, "tfss-") === false) {
echo "\nThis is already an internal file, skipping...";
continue;
}
$newFileName = str_replace("tfss-", "", $fileName);
$binaryFile = file_get_contents($parseFile->getURL());
$newFile = ParseFile::createFromData($binaryFile, $newFileName);
$entryWithFile->set($fileField, $newFile);
$entryWithFile->save(true);
echo "\nFile saved\n";
}
catch (Exception $e) {
// The conection with mongo or the server could be off for some second, let's retry it ;)
sleep(10);
continue;
}
}
echo "\n";
echo "END!";
?>
so if you configure $fileField and $class as before, and you can open 3 threads and run:
php migrator.php 0 3 "imageProfile" "_User"
php migrator.php 1 3 "imageProfile" "_User"
php migrator.php 2 3 "imageProfile" "_User"
so you will have loops running like:
object 0, 3, 6
object 1, 4, 7
object 2, 5, 8
Good luck, and be quick! It's going to shut down in a few days.

How to download gpx files in Laravel 5.2

Good afternoon everyone !
I have this simple code in the controller
public function descargarRutaGPX($id){
$buscar = Ruta::find($id);
$file = Storage::get('ddfbdsfv.gpx');
echo $file;
}
If the file exists the browser show "Preppend text" , but if the file doesn't exists the browser shows FileNotFoundException in FilesystemAdapter.php line 61.
Could anyone help to me ?
UPDATED
$buscar = Ruta::find($id);
if (Storage::has('aaaa.gpx')) {
$file = Storage::get('aaaa.gpx');
return response()->download($file);
}else{
echo "NO";
}
This is the error.
The file "Prepended Text" does not exist
You'll probably want to check and make sure the file exists as well as download the file if it does. Try changing your code to the following
public function descargarRutaGPX($id){
$buscar = Ruta::find($id);
If (Storage::has('ddfbdsfv.gpx') {
$file = Storage::get('ddfbdsfv.gpx');
return response()->download($file);
} else {
// file not found. Do something to alert the user
}
}

How do I make different sessions on the site

I am using session_start ();
I want to make each page or each folder has its own session
Example:
When you request mysite.com/A opens new session
When asked mysite.com/B opens new session
How so?
It is not clear as to what you mean by opening new session in each folder. If you meant to say that you want a session variable on each folder and the value of this variable should change from folder to folder:
Say, you have a session variable $_SESSION['folderName'] and you want to achieve:
$_SESSION['folderName'] = 'A'; // When in folder mysite.com/A
$_SESSION['folderName'] = 'B'; // When in folder mysite.com/B
Then you can do:
$_SERVER['REQUEST_URI_PATH'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$segments = explode('/', $_SERVER['REQUEST_URI_PATH']);
//now when the URL is mysite.com/A, $segments[0] will
// have mysite.com and $segments[1] will have 'A'
So, on each file on each folder, you can do:
<?
session_start();
$_SERVER['REQUEST_URI_PATH'] = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$segments = explode('/', $_SERVER['REQUEST_URI_PATH']);
$_SESSION['folderName'] = $segments[1];
?>

Resources