Both methods are valid and will work, but using an array to store the URLs is more efficient as it will only use one session key instead of multiple keys. Additionally, it will be easier to manage and manipulate the data in an array.
Here's an example of how to implement this solution:
// Initialize the array if it doesn't exist
if (!session()->has('unique_views')) {
session(['unique_views' => []]);
}
// Add the current page URL to the array if it doesn't already exist
$currentUrl = request()->url();
if (!in_array($currentUrl, session('unique_views'))) {
session()->push('unique_views', $currentUrl);
}
This code checks if the unique_views array exists in the session and initializes it if it doesn't. Then, it gets the current page URL and checks if it already exists in the array. If it doesn't, it adds it to the array using the push method.
Note that this code assumes that you're using Laravel and that the session() and request() functions are available. If you're using a different framework or plain PHP, you'll need to adjust the code accordingly.