0

I am trying to make this variable equal to the user id and then a random integer that comes straight after the user id. How would I do this as my code doesn't seem to work?

$parentid = $_SESSION['user_name'] + rand();

Thanks

James Walsh
  • 41
  • 2
  • 10

2 Answers2

1

This is beginner error, string concat is done using a single dot .

Anyway I suggest you using mt_rand() function that is 4 time faster than the oldest rand() function

So your code should be something like this

$parentid = $_SESSION['user_name'] . mt_rand();
0

For a more "strict" guideline, you could use sprintf or str_replace()

$parentid = sprintf('%s%d', $_SESSION['username'], rand());
q.Then
  • 2,743
  • 1
  • 21
  • 31