0

I have 2 pages, signup.php and errors.php in errors.php I have:

$signuperrors = array(username, password, repassword, email);

and I store errors in this array. I want to use this array on signup.php It is a dumb question probably because I recently started php. Thanks!

1
  • 1
    Not sure what you mean but session variables? Commented Aug 11, 2017 at 16:39

2 Answers 2

1

You mean session.. It is like a variable but saved in a memory of php server(Apache)

First is declare your session on all of your pages that uses the session variables before html tag(anywhere)

<?php
session_start();
?>

Then start declaring your variables like this

$_SESSION["signuperrors"] = array(username, password, repassword, email);
$_SESSION["sample"] = "sample string";

Hope this helps

Then you can now access those values to other pages

Sample:

print_r($_SESSION["signuperrors"]); 
echo $_SESSION["sample"];
Sign up to request clarification or add additional context in comments.

2 Comments

So can I change array values like $_SESSION["username"] = "patato" or is there a spesific way to do it. and getting the spesific value of an array with session.
you can do just as a regular variable you are using, and if you want to remove or decided not to use a certain session variable, you can use unset( $_SESSION["username"]) or user session_destroy() to remove all sessions..
0

You should look into https://www.w3schools.com/php/php_sessions.asp. further reading: https://web.archive.org/web/20080707052007/http://www.phpriot.com/articles/intro-php-sessions/7

1 Comment

Need answer here instead of only the link because the link can be broken

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.