Pretty simple but another said you dont pass session variables through the url bar 1.You dont need to because a session is passed throughout the whole website from header when you put in header file 2.security risks
Here is first page code
$url = "//localhost/main.php?email=" . urlencode[$email_address] . "&eventid=" . urlencode[$event_id];
2nd page when getting the variables from the url bar is:
if[isset[$_GET['email']] && !empty[$_GET['email']] AND isset[$_GET['eventid']] && !empty[$_GET['eventid']]]{
////do whatever here
}
Now if you want to do it the proper way of using the session you created then ignore my above code and call the session variables on the second page for instance create a session on the first page lets say for example:
$_SESSION['WEB_SES'] = $email_address . "^" . $event_id;
obvious that you would have already assigned values to the session variables in the code above, you can call the session name whatever you want to i just used the example web_ses , the second page all you need to do is start a session and see if the session is there and check the variables and do whatever with them, example:
session_start[];
if [isset[$_SESSION['WEB_SES']]]{
$Array = explode["^", $_SESSION['WEB_SES']];
$email = $Array[0];
$event_id = $Array[1]
echo "$email";
echo "$event_id";
}
Like I said before the good thing about sessions are they can be carried throughout the entire website if this type of code in put in the header file that gets called upon on all pages that load, you can simple use the variable wherever and whenever. Hope this helps :]
5 Years Ago
I passed two parameters in the URL. Now I need to retrieve the parameters log_id and dogID onto the next page to process a form.
But I can retrieve the first parameter but i cannot retrieve the second parameter.
Im using
$log_id= $_SESSION["userid"];
$dogID = $_SESSION["dogID"];
Is there another way to get this?
Edited 5 Years Ago by happygeek because: moved
Recommended Answers
Hi,
can you show the previous step, i.e. the code used to set the session variables?
Jump to Post
If you append parameters to the landing page:
dogReview.php?u=USER&dogID=123
Then you can access those values by using
$_GET
:$user = $_GET['u']; $dogID = $_GET['dogID'];
$_SESSION
, instead, is reserved to values set in the session handler.See:
Jump to Post
All 6 Replies
cereal 1,524 Nearly a Senior Poster
Featured Poster Hi, can you show the previous step, i.e. the code used to set the session variables?
5 Years Ago
Hello there The previous step was this to get to the other page
echo["
Add Your Review
"];
I tried using this as well but nothing seems to work..
$dogID = $_GET["dogID"];
cereal 1,524 Nearly a Senior Poster Featured Poster
5 Years Ago
5 Years Ago
that still doesnt seem to work
I keep getting the error:
Column 'dog_reviewed' cannot be null.
My code to insert into the db is :
if[$stmt = mysqli_prepare[$mysqli,"INSERT INTO DOG_REVIEW[dog_reviewed,id,disciplineComments, challengesFaced,comments,Temperament,healthConcerns]VALUES[?, ?, ?, ?, ?, ?, ?]"]]
Where im getting the values from the url for the dog [dog_reviewed] thats being reviewed, and the user[id] that is revewing.
Am I missing something? Or doing this completly wrong?
Im new to php and learning as I go along.
cereal 1,524 Nearly a Senior Poster Featured Poster
5 Years AgoAm I missing something? Or doing this completly wrong?
It's difficult to say because I don't see the current code you are using. On top of dogReview.php page, right after session_start[]
set var_dump[]
to show $_GET and $_SESSION contents:
echo "";
var_dump[$_GET, $_SESSION];
echo "
";
You should be able to see what is sent through the GET request [appending the parameters to the url] and the contents of the current session. If it does not help show the code of this page.
5 Years Ago
How about when you get to your page dogReview.php
the u=$username and the dogID the should show the current value of the up in the brower url
Reply to this topic
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.