-1

I am working with a PHP and HTML project and have two scenarios.

Scenario 1

The user generates a URL with a GUID that identifies the user. The GUID is stored in a database.

scenario 2

If the user visits the page with an already generated GUID I want to be able to GET the GUID from the URL and use it in my whole project.

The user's URL will look like this

http://localhost/mini/album/index/GUID eg http://localhost/mini/album/index/6957da07-7cd0-4f0e-a300-fa9ecdf79d0a

I know how I'll get the guid from url and when the user has generated a new guid but where do I store it temporary as long as the user visits the page? I am thinking about using global variables, HTML5 Local Storage or if its possible to use sessions for this. What do think is the best solution and do you have any other suggestions?

tereško
  • 58,060
  • 25
  • 98
  • 150
Xtreme
  • 1,601
  • 7
  • 27
  • 59
  • Why you are not using session_start() ? The session ends when browser is closed. – Carca Dec 10 '14 at 19:34
  • PHP session would be the way to go. Just use session_start() like CarcaBot said and then set the var: $_SESSION['GUID'] = $guid – erikvimz Dec 10 '14 at 20:07

2 Answers2

0

Look into PHP Sessions, as well as some of the possible security problems, particularly with adding the GUID to the URL.

<?php
session_start()
$_SESSION['GUID'] = get_guid();
....
echo "GUID is {$_SESSION['GUID']}";

If it's used for identifying the user, it should generally not be visible/able to be modified by the client. Save HTML5 LocalStorage and Cookies for more trivial things like preferences or cached data.

Curtis Mattoon
  • 4,642
  • 2
  • 27
  • 34
0

Use apache rewrite. In your .htaccess file, do something like this:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^mini/album/index/([A-Za-z0-9-]+)$ /php_script_that_you_use_for_saving_a_guid.php?GUID=$1 [QSA,L]

Where GUID is the $_GET variable. Get it and store it

Rename "php_script_that_you_use_for_saving_a_guid.php" to the actual file and path, etc. that you will use to save GUIDs.

skidadon
  • 547
  • 4
  • 7