<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: mostafa amine briere</title>
    <description>The latest articles on Forem by mostafa amine briere (@mostafaamine).</description>
    <link>https://forem.com/mostafaamine</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F803404%2Ff930893e-de48-4838-81b7-08bb93b3e7ff.png</url>
      <title>Forem: mostafa amine briere</title>
      <link>https://forem.com/mostafaamine</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mostafaamine"/>
    <language>en</language>
    <item>
      <title>How to use Laravel Session</title>
      <dc:creator>mostafa amine briere</dc:creator>
      <pubDate>Fri, 09 Dec 2022 12:19:59 +0000</pubDate>
      <link>https://forem.com/mostafaamine/how-to-use-laravel-session-1794</link>
      <guid>https://forem.com/mostafaamine/how-to-use-laravel-session-1794</guid>
      <description>&lt;h1&gt;
  
  
  What is a Session?
&lt;/h1&gt;

&lt;p&gt;Sessions are used to store information about the user temporarily across the requests.&lt;/p&gt;

&lt;h1&gt;
  
  
  How to configure your session file in laravel
&lt;/h1&gt;

&lt;p&gt;The session configuration file is stored in &lt;code&gt;config/session.php&lt;/code&gt;, from this file you can change the session driver, session lifetime, and more.&lt;/p&gt;

&lt;p&gt;For example, if you want to &lt;code&gt;encrypt&lt;/code&gt; all your session data you can configure it easily from the &lt;code&gt;config/session.php&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F89wj0q5lf27wplptauvk.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F89wj0q5lf27wplptauvk.jpeg" alt="session file in laravel" width="800" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Change Session driver
&lt;/h3&gt;

&lt;p&gt;By default, laravel is configured to use the &lt;code&gt;file&lt;/code&gt; session driver which is store your sessions files in &lt;code&gt;storage/framework/sessions&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft5ad8euytc6m6shfhcko.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft5ad8euytc6m6shfhcko.jpeg" alt="Change Session driver" width="511" height="812"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But you can change the path where sessions are saved and you can also change the session driver by drivers provided by laravel from the &lt;code&gt;config/session.php&lt;/code&gt;file.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;cookie&lt;/code&gt;: sessions are stored in secure, encrypted cookies.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;database&lt;/code&gt;: sessions are stored in a relational database.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;memcached / redis&lt;/code&gt;: sessions are stored in one of these fast, cache-based stores.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;dynamodb&lt;/code&gt;: sessions are stored in AWS DynamoDB.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;array&lt;/code&gt;: sessions are stored in a PHP array and will not be persisted.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, You can read more about the &lt;code&gt;Driver Prerequisites&lt;/code&gt; if you want to store the sessions in a &lt;code&gt;database&lt;/code&gt; from this &lt;a href="https://laravel.com/docs/9.x/session#driver-prerequisites" rel="noopener noreferrer"&gt;Link&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  How to Store And Retrieve Sessions
&lt;/h1&gt;

&lt;p&gt;If you want to store/retrieve sessions in laravel there are two possible ways&lt;/p&gt;

&lt;h2&gt;
  
  
  1. From &lt;code&gt;session()&lt;/code&gt; helper method
&lt;/h2&gt;

&lt;p&gt;When you declare the &lt;code&gt;session()&lt;/code&gt; helper with an array of key/values pairs those values will be stored in the session :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Store data in the session
session(['key' =&amp;gt; 'value']);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But if you declare the &lt;code&gt;session()&lt;/code&gt; helper with a single string argument it will return the value of that session&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;session('key') // returns the value
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Check if the session data is stored
&lt;/h3&gt;

&lt;p&gt;If you want to check If An Item Exists In The Session you can use the &lt;code&gt;has()&lt;/code&gt; method returns ´true´ if the item is present and is &lt;code&gt;not null&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$request-&amp;gt;session()-&amp;gt;has('key') // true or false
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And if you want To check if an item is present in the session, even if its value is &lt;code&gt;null&lt;/code&gt;, you may use the &lt;code&gt;exists&lt;/code&gt; method:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$request-&amp;gt;session()-&amp;gt;exists('key')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. From the &lt;code&gt;request&lt;/code&gt; instance
&lt;/h2&gt;

&lt;p&gt;You can store the session with a &lt;code&gt;request&lt;/code&gt; instance or from the &lt;code&gt;request()&lt;/code&gt; helper method which returns the current request instance :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$request-&amp;gt;session()-&amp;gt;put('key' , 'value');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also retrieve session data :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$value = $request-&amp;gt;session()-&amp;gt;get('key');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Retrieving &amp;amp; Deleting An Item
&lt;/h3&gt;

&lt;p&gt;If you want to &lt;code&gt;retrieve&lt;/code&gt; and &lt;code&gt;delete&lt;/code&gt; an item in a single statement you can use the &lt;code&gt;pull()&lt;/code&gt; method :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$value = request()-&amp;gt;session()-&amp;gt;pull('name');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  How to delete sessions Data
&lt;/h1&gt;

&lt;p&gt;To delete sessions data you can use the &lt;code&gt;forget()&lt;/code&gt; method :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$request-&amp;gt;session()-&amp;gt;forget('key');
$request-&amp;gt;session()-&amp;gt;forget(['key1', 'key2']);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And If you would like to remove all data from the session, you may use the &lt;code&gt;flush()&lt;/code&gt; method :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$request-&amp;gt;session()-&amp;gt;flush();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  How to use Session Flash
&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;Flash data&lt;/code&gt; is session data that is only kept for a single request. It is most often used for success/failure messages that automatically disappear after a page refresh.&lt;/p&gt;

&lt;p&gt;To use flash data, laravel provides a helpful method called &lt;code&gt;flash()&lt;/code&gt; that accepts a key and its value :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;request-&amp;gt;session()-&amp;gt;flash('status' , 'Article Added');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  How to protect your web application from session attacks
&lt;/h1&gt;

&lt;h3&gt;
  
  
  Regenerating The Session ID
&lt;/h3&gt;

&lt;p&gt;Session regeneration is about setting a new value of a session ID It mainly helps prevent &lt;code&gt;session fixation attacks&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Session fixation attacks is where a malicious user tries to exploit the vulnerability in a system to fixate (set) the session ID of another user. By doing so, they will get complete access as the original user and be able to do tasks that would otherwise require authentication.&lt;/p&gt;

&lt;p&gt;And because of that Laravel automatically regenerates the session ID during authentication if you are using one of the &lt;code&gt;Laravel starter kits&lt;/code&gt; (&lt;a href="https://laravel.com/docs/9.x/starter-kits" rel="noopener noreferrer"&gt;read more&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;but you can manually regenerate the session ID with the &lt;code&gt;regenerate()&lt;/code&gt; method :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$request-&amp;gt;session()-&amp;gt;regenerate();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;laravel also provides another method that &lt;code&gt;regenerates&lt;/code&gt; session ID and &lt;code&gt;removes&lt;/code&gt; all previous session data&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$request-&amp;gt;session()-&amp;gt;invalidate();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>php</category>
      <category>laravel</category>
      <category>security</category>
      <category>webdev</category>
    </item>
    <item>
      <title>use placeholder website to generate images</title>
      <dc:creator>mostafa amine briere</dc:creator>
      <pubDate>Wed, 23 Feb 2022 22:48:49 +0000</pubDate>
      <link>https://forem.com/mostafaamine/use-placeholder-website-to-generate-images-3jd4</link>
      <guid>https://forem.com/mostafaamine/use-placeholder-website-to-generate-images-3jd4</guid>
      <description>&lt;h2&gt;
  
  
  1-How to use placeholder website to generate photos with the desired size :
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;First, let's see why you must use this website : 
&amp;gt; placeholder website allows you to use pictures in various sizes,
&amp;gt;You may also choose the text, in order to save time in finding images without having to put an actual image&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2-How to use the website :
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;All you have to do is write the code for the site, followed by some instructions, we will see them&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Image size :&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src="https://via.placeholder.com/150" alt=""&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftq0gxcfcwbi399p0lmkh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftq0gxcfcwbi399p0lmkh.png" alt="Image description" width="150" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Determine the height and width :&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src="https://via.placeholder.com/600x250" alt=""&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F21oc3u5a45gjtpuoqnkh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F21oc3u5a45gjtpuoqnkh.png" alt="Image description" width="600" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Colors :&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src="https://via.placeholder.com/300x250/ffa500" alt=""&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzggchj37yhrb2bhm4x1z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzggchj37yhrb2bhm4x1z.png" alt="Image description" width="300" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To change the text color :&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src="https://via.placeholder.com/300x250/ffa500/FFF" alt=""&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7jesyya57388a8pfb6u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fh7jesyya57388a8pfb6u.png" alt="Image description" width="300" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;To write text :&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;img src="https://via.placeholder.com/300x250/ffa500/FFF?text=mostafa+amine" alt=""&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft2qhe5xm6r4gywphpic2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ft2qhe5xm6r4gywphpic2.png" alt="Image description" width="300" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
