define https for wildcard domains - https

I have a DB of users and I'm dynamically creating pages. So I'm verifying that the user exists in the DB. I need one page to be https, but I'm not understanding how to define that.
I have the following:
// define subdomain here
$server = $_SERVER['HTTP_HOST'];
$sub = str_replace('the14dayreset.com', '', $server);
$sub = preg_replace('%^www\.%msi', '', $sub);
$user = str_replace('.', '', $sub);
if(empty($user)) {
header("Location: https://14dayreset.the14dayreset.com/order-now1.php");
exit;
}
If I use $_SERVER['HTTPS'], then I lose the subdomain.
What is the best way to do this?
Thanks in advance
Pattie

Related

Find a Session by ID Substring in Laravel 8

Im trying to find a session by PART of its ID in laravel.
I only have the first part of the id, and I need to find if the session has a key/value associated with it.
I have tried various forms of the below code. Its fairly simple but not sure if possible in laravel.
Note
Im not sure if this helps or not, but the laravel system is using file based sessions, not DB based sessions.
$value = 'do i have this value';
// Session::all()->whereLike('id','aVhN8u' . '%')->get();
foreach( Session::all()->where('id')->startsWith('aVhN8u') as $session)
{
if($session->has('key', $value)
{
// Do something interesting
}
}
Something like this should work.
use Illuminate\Support\Str;
$value = 'my cool value';
$prefix = 'aVhN8u';
$stored = session()->all();
$filtered = collect($stored)->filter(function ($session, $key) use ($prefix, $value) {
return Str::startsWith($key, $prefix) && $session == $value;
})->all();

How to get url from dropbox using flysystem?

Hello i has upload my file using laravel5, https://github.com/GrahamCampbell/Laravel-Dropbox integrate to dropbox and has succeed, and then i want to get the url for my imgsrc="" on the frontend, How i can get thats url?
dd(Flysystem::get('avatars/kenshin.jpg'));
Where is the url for imgsrc?
Assuming you already created a service provider for custom filesystem.
If you don't know how to do that the doc is Here
Route::get('/dropbox',function()
{
$filename = '/text1.txt';
$adapter = \Storage::disk('dropbox')->getAdapter();
$client = $adapter->getClient();
$link = $client->createTemporaryDirectLink($filename);
return <<<EOT
Link
EOT;
});
PLEASE NOTE THAT you have to prefix a "\" slash on the filename or else it will thrown an exception.
I save a shared link while saving a new resource. Like so
$path = Storage::disk('dropbox')->putFile('/images', storage_path('images/' . $imageName));
$adapter = \Storage::disk('dropbox')->getDriver()->getAdapter();
$client = $adapter->getClient();
$link = $client->createSharedLinkWithSettings($path);
$newsdigest = NewsDigest::create($request->all('title','type','source', 'article') + [
'reading_attachment' => $link['url']
]);
Create another route for a method in your controller and pass the file name that you want to access from dropbox with the route.
Use getFile() method in your controller and pass the filename to the variable.
public function getFile($file_name)
{
$client = new Client('dropbox.token','dropbox.appName');
$this->filesystem = new Filesystem(new Dropbox($client, '/path'));
try{
$file = $this->filesystem->read($file_name);
}catch (\Dropbox\Exception $e){
return Response::json("{'message' => 'File not found'}", 404);
}
$response = Response::make($file, 200);
return $response;
}
The best way I found to upload your file in Dropbox and even get share files link in your PHP or Laravel or any PHP framework is by using this package
composer require kunalvarma05/dropbox-php-sdk
This is how to use it, an example I made using Laravel:

Session not remember, and why the session created each time I load the page?

I start to work with my project using laravel 5. I realized that it work fine in my local directory with session after I login to my site, But I just know that I got problem when I hosted my project to server. After I login each time, the session could not remember and recreated each time I loan the page. That cause the problem to me.
Laravel Login
public function postLogin(){
$hit = 0;
if(Request::ajax()){
$pw = Request::input('pw');
if(!empty($pw)){
$admin_pass = AdminPassword::first(['admin_pass']);
$ip_address = Request::ip();
if(!empty($admin_pass) && trim($admin_pass->admin_pass) == trim($pw)){
if(Auth::attempt(['username' => Request::input('username'), 'password' => Request::input('password'),'status'=>1])){
try{
$user = Auth::user();
$user->last_login = date('Y-m-d H:i:s');
$user->login_ip = $ip_address;
$user->save();
$permissions = Auth::user()->permission;
if(!empty($permissions) && count($permissions) >0){
session(['ROLE_PERMISSION'=>$permissions]);
}
$failed = FailedLogin::whereRaw('ip_address = INET_ATON(\''.$ip_address.'\')')->first();
if(!empty($failed)){
$failed->delete();
}
}catch (\Exception $ex){}
$url = Request::session()->pull('url.intended', '/');
return ['url'=>$url,'msg'=>'Successfully.','status'=>true,'hit'=>$hit];
}else{
$hit = $this->updateFailedLogin($ip_address,Request::input('username'));
}
}else{
$hit = $this->updateFailedLogin($ip_address,Request::input('username'));
}
}
}else{
return redirect()->route('login');
}
return ['url'=>'','msg'=>'Try again.','status'=>false,'hit'=>$hit];
}
Please help me out. This is the final step of my project.
Thank you in advanced.
It's possible you have SESSION_DRIVER in your .env set to file - depending on your hosting environment, this could mean that your session isn't persisting due to each request being served from a different file server (common in cloud environments).
Try changing your SESSION_DRIVER to database.
Did you put the
session_start();
in all your pages?
If not it might be your problem, I d suggest you to add this in your index directly

Joomla 2.5 -- get sef url from itemid

How can I find the correct SEF url of an Menuitem, based on its ID?
$link = JRoute::_( $menus->getItem( $id )->link.'&lang='.$languages[ $code ]->sef, true );
delivers something like:
http://localhost/<path>/component/content/?view=featured
but what i want is the url generated from the menu, which is:
http://localhost/<path>/<lang-sef-code>/<path>
How can I achive this?
I finally found the solution for the problem I had.
$languages = JLanguageHelper::getLanguages('lang_code');
foreach ($associations as $code => $id ) {
item = $menus->getItem( $id );
$link = JRoute::_( 'index.php?lang='.$languages[ $code ]->sef.'&Itemid='.$item->id );
}
this delivers:
http://localhost/<lang>/<path-to-link>
I noticed that when dealing with SEF URLs than the order in which vars are given to the JRoute::_() method are decisive. I hope to help somebody who got some problems with this too.
Greetings
philipp

Checking for Magento login on external page

I'm hitting a wall here while trying to access items from Magento on an external page (same server, same domain, etc, etc). I want to see if the user is logged into Magento before showing them certain parts on the site.
Keep in mind that this code exists outside of Magento.
Mage::app("default");
Mage::getSingleton("core/session", array("name" => "frontend"));
if (empty($session))
{
$session = Mage::getSingleton("customer/session");
}
if($session->isLoggedIn())
echo "hi";
$cart = Mage::helper('checkout/cart')->getCart()->getItemsCount();
echo $cart;
$cart returns 0, where I definitely have products in my cart. isLoggedIn() also returns false. What am I doing wrong here? Is there an option in Magento that I need to turn on or off to be able to access this information outside of Magento?
Using the code above, I created a php file in the Magento folder. From there, added the number of items in the cart and whether you were logged in or not to an array and encoded it as json. I used some jquery on my external page to grab the file and pull the data I needed.
Not quite the ideal situation, but it works for now.
Are you including Mage.php (which defines getSingleton)?
require_once ($_SERVER['DOCUMENT_ROOT'] . '/app/Mage.php');
What does $session have in it after the getSingleton() call?
print_r ($session);
EDIT: I tried this on my end and was not able to get accurate isLoggedIn() or getItemsCount() data. When I dumped out $session its showing all the fields as 'protected.'
I'm not interested in requiring the user to log in...I merely want to access data from the already logged in session.
Anyone else have any thoughts on this? All the examples out there seem to be pre 1.4.x.
require_once "app/Mage.php";
umask(0);
Mage::app();
// require_once $_SERVER['DOCUMENT_ROOT'] . "/mage1/app/Mage.php";
// Customer Information
$firstname = "krishana";
$lastname = "singh";
$email = "krish.bhati#gmail.com";
$password = "myverysecretpassword";
// Website and Store details
$websiteId = Mage::app()->getWebsite()->getId();
$store = Mage::app()->getStore();
$customer = Mage::getModel("customer/customer");
$customer->website_id = $websiteId;
$customer->setStore($store);
$mageRunCode = isset ( $_SERVER ['MAGE_RUN_CODE'] ) ? $_SERVER ['MAGE_RUN_CODE'] : '';
$mageRunType = isset ( $_SERVER ['MAGE_RUN_TYPE'] ) ? $_SERVER ['MAGE_RUN_TYPE'] : 'store';
$app = Mage::app ( $mageRunCode, $mageRunType );
Mage::getSingleton('core/session', array('name' => 'frontend'));
$session = Mage::getSingleton('customer/session');
$session->start();
$customer->loadByEmail($email);
$customer_id= $customer->getId();
if($customer_id){
Mage_Core_Model_Session_Abstract_Varien::start();
$session->login($email, $password);
$session->setCustomerAsLoggedIn($session->getCustomer());
echo $session->isLoggedIn() ? $session->getCustomer()->getName().' is online!' : 'not logged in';
}

Resources