<?php
session_id('hello1');
session_start();
?>
The code above will change “session_id”.
I like to change session_id after reading the session_id is given.
The code below doesn’t work correctly, but I hope it shows what I want.
Thank you, John_Betong. for your code, but I don’t quite understand your code although I test it and I read it as you recommend “how to use sessions”.
I felt I don’t unserstand fully although I read it.
At the moment I like to say what I want more exactly.
I like to change session_id() instead of $_SESSION[''each session"]
in other words, I like to use my own session value for session_id
if I use session_id(‘my own session value’) before session_start like the code below, the session_id value is made by me.
[code]
<?php session_id('hello1');
session_start();
?>
[/code].but the code above works in the very first part of a web page
I like to make another session_id in the middle of a page after the old session(‘old session_id"’) reading for getting some session values by using $_SESSION[''each session"].
<?php
session_id('hello1');
session_start();
$old_sessionid = session_id();
session_regenerate_id('hello2');
$new_sessionid = session_id();
echo "Old Session: $old_sessionid<br />";
echo "New Session: $new_sessionid<br />";
?>The code above doesn’t work as my expectation but it shows what I want. I like to make the value of the new session_id as “hello2” instead of the hash value like “f2d98b2e424312e913b238b345116da9”.
Not all have optional arguments or defaults, but that’s how they are when a function does have them.
Most if not all documentation pages have Examples and User Contributed Notes that are worth looking at too.
So string session_id ([ string $id ] )
the function returns a string
the function takes an optional string parameter
bool session_regenerate_id ([ bool $delete_old_session = false ] )
the function returns a boolean
the function takes an optional boolean parameter, the value will be false if one isn’t provided.
The “string” before the function name (or bool, array, mixed, etc. as the case may be) is the data type the function returns, not part of the function name.
[quote=“Mittineague, post:8, topic:226165, full:true”]
The “string” before the function name (or bool, array, mixed, etc. as the case may be) is the data type the function returns, not part of the function name.
[/quote] Now I understand “string” means data type. and “session_id” is a function name.
[quote=“Mittineague, post:8, topic:226165, full:true”]
string session_id ([ string $id ] )
the function returns a string[/quote]
I like to ask you about the word returns.
echo $sessid;
?>[/code]I can say it produces “hello1” or it echos “hello1”.
returns means “produces” or “echos”?
[quote=“Mittineague, post:8, topic:226165, full:true”]
string session_id ([ string $id ] )
the function takes an optional string parameter[/quote]
So is [ string $id ] an optional string parameter?
I think “string” in [ string $id ] is a data type.
Funny, but as simple as “return” is, I have some trouble coming up with a good explanation.
Some functions “do stuff” and don’t return anything (though IMHO it’s usually a good idea to whether or not it will be used). and you might see “void”.
But usually they do something. eg. add numbers together, change letters to uppercase, validate an email address, etc. etc.
For these, usually whatever the function does, with whatever is passed to it, is wanted so it can be used. So after the function does its thing it returns the change or at least indicates success.
yes, in the PHP documentation’s “synopsis” / “description” square brackets are used to signify optional parameters.