py_script
py_script

Reputation: 830

Take info of current page when pressing a button

I have a question for php. I am sure it has already answered but I can't express it to search. So, I have a page which is actually a user profile. In this page there is a button.

When I press this key I want somehow to take the id of the user the the profile belongs.

I think in jsp you can do this with Request object, but I am not sure.

Upvotes: 0

Views: 66

Answers (2)

Eric Herlitz
Eric Herlitz

Reputation: 26257

Are you running your page in a framework? Do you use sessions?

Php doesn't store any information about the page or user object unless you tell it to.

If you however have an object with userdata you can simply access it like this

print_r($userObj);

And if there are some data in and userId property you might access it like this

$userObj->userId

Upvotes: 0

Cfreak
Cfreak

Reputation: 19309

If it's a form submit put the user id in a hidden input on the page. Something like:

<input type="hidden" name="user_id" value="<?php echo $your_user_id; ?>" />

Then when you click the button to submit your form it will be available in the variable $_POST['user_id'] if you used the POST method or $_GET['user_id'] if you used the GET method.

If you want to do it without submitting a form you probably need to use Javascript to make an AJAX call.

Upvotes: 2

Related Questions