Does "register" mean "assign" in PHP?

pae2
pae2 used Ask the Experts™
on
Does "register" mean "assign" values to the variables in the following context?

"In this script, you'll start a session and register the font_family and font_size variables."
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
In that context you are being told to:

1. Start a session.
2. Create two variables: font_family and font_size.  
3. Register those two variables as session variables.

Author

Commented:
So does "register" just mean "make," in general?

Author

Commented:
All I want to know is what the word "register" means.
Exploring SharePoint 2016

Explore SharePoint 2016, the web-based, collaborative platform that integrates with Microsoft Office to provide intranets, secure document management, and collaboration so you can develop your online and offline capabilities.

In this context register just means to make a variable equal to. Atleast thats what it sounds like.

Something like this
<?php
start_session();
$font_family = "Arial";
$font_size = "11px";



?>

Open in new window

Commented:
No, in this context, registering a variable does not mean assigning a variable. it's referring to the use of tthe session_register() function, which is no longer supported. It is a deprecated function. But check out the session_register() function documentation on the PHP site to see what it used to do. You no longer need to use it, though.
Ahh gonzo thanks for clarifying, wow never knew about that function before.

So I guess the code needs to be more like:
<?php 

start_session(); 
$_SESSION["font_family"] = "Arial"; 
$_SESSION["font_size"] = "11px"; 
 
?>

Open in new window

Author

Commented:
@gr8gonzo, the PHP site says this: "session_register — Register one or more global variables with the current session"; what does Register mean in this case?
You need to read up about what a session is in PHP : http://www.w3schools.com/PHP/php_sessions.asp

In short a PHP session lets you save an instance of a variable value onto each of the people who are you looking at the website, which are unique to that person if you want it to be.

After doing start_session()

When you "register a global variable with the current session" it means you are to store the value onto the a variable which exists only for the duration of this session for the person who is currently looking at that page (when the user closes his browser OR when you use session_destroy())

Say you have a page which has something like

<?php  
 //index.phg
start_session();  
if( isset($_GET["font"]) ) $_SESSION["font_family"] = $_GET["font"];

echo "<a style='font-family:\"".  = $_GET["font"];
 ."\";'>Hi there!</a>";
 
?>

And then you show it to two people (me and bob)

When I enter the URL for the website I type www.yourwebsite.com/index.php?font=Arial and the variable "font_family" in my session will be set to Arial, then if I goto just www.yourwebsite.com/index.php again then it will read my own unique font_family variable and show me the text "Hi there!" in the font Arial.

But lets say at the same time Bob looks at the website, and instaed of using font=Arial he uses font=Courier New

Then his font_family variable gets saved as "Courier New" on his PHP session. When he refreshes the page for "www.yourwebsite.com/index.php" on his end the font will be Courier New still, but at the same time if I refresh the page on my end AFTER all the things Bob did, the font for my end will still appear as Arial.

I hope this kinda explains it... Its abit difficult to explain. Read that website though! It teaches you the basics of PHP sessions.
I just read now the question wasn't targetted at me, sorry about butting in.
Mistakes in my code in example ::: It should be this:
<?php  
 //index.php
start_session();  
if( isset($_GET["font"]) ) $_SESSION["font_family"] = $_GET["font"];

echo "<a style='font-family:\"". $_SESSION["font_family"] ."\";'>Hi there!</a>";
  
?>

Open in new window

Author

Commented:
SleepinDevil, that's what I was looking for!! I am clear on it now.

Yes, I know I need to read more. I am new to PHP.

Thanks for the help!!!
No worries!! I am glad to have helped a beginner. I hope PHP becomes as valuable to you as it has become to me. Good luck in your scripting!! Thanks for the points!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial