Jump to content

Using a variable in multiple files


Ache

Recommended Posts

I have a html form that sends a variable (UniqueID) to a php file. The php file starts with:

// Get user number$prk = $_POST['prk'];include ("user-menu.php");include ("config.php");

Sofar everything is working. user-menu-php is a menu that I show on all pages the user has access to after login.What I want is somehow to remember the UniqueID so that when a user picks a option from the menu and a new page opens, I can use UniqueID on that page.I have tried with global variables and session but I can't get either to work. (globals is on on the server)Any idea on how I can do it?

Link to comment
Share on other sites

Keep learning about sessions. This is exactly that they exist for. Something like:login.php

if (!empty($_POST['prk'])) {   session_start();   $_SESSION['user'] = $_POST['prk'];}// etc.

another.php

session_start(); if (!empty($_SESSION['user'])) {   // USER IS LOGGED IN}// etc.

Link to comment
Share on other sites

Thank you very much. I got it working now. And yes, I keep learning. Only started to learn PHP very recently, And I am very surprised what I can do already (with a little help from people here). Looking at your example code I now know what I did wrong when I tried with a session. I did not start it in the "another.php". Ah well, another problem tackled and I learned something :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...