php code to only allow rightful users (entry creators) to view a page

By: Corey Lee | Asked: 08/06/2023
ForumsCategory: Code Helpphp code to only allow rightful users (entry creators) to view a page
Corey Lee asked 9 months ago
Please help.  I have a page that runs PHP code to display customized content based on the entry key, such as, where 21hzx is the entry key (form id is 6). The problem is that anyone with the entry key can view the content at What's the PHP code that only allows rightful users (entry creators) to view the content? A user can have multiple entries with a form (form id is 6).  Many thanks in advance.     
2 Answers
Walter JonesWalter Jones answered 9 months ago
Are they getting linked to the entry id so they can edit the entry, or are they just viewing the entry?  

If they are just viewing data, setup a view and filter it userid=current_user .
Corey Lee answered 9 months ago
Thanks for your prompt response. They just are viewing their own entry. However, I need to do it via PHP statement, given my page is built with PHP code. It begins with the following.
$view = $_GET['view']; 
$entry_id = FrmEntry::getOne($view);
$entry_id = FrmProEntriesController::show_entry_shortcode( array( 'id' => $view, 'format' => 'array' ) );
$entry_id = json_decode(json_encode($entry_id), True);
Before retrieving the entry data, it needs to verify if this entry was created by this user with a form (form id=6). Any suggestion? Thanks.
Victor Font replied 9 months ago

Why are you overriding $entry_id? Assuming 'view' is a parameter that has an entry id, you are returning the full form entry with getOne. Then you immediately over write the variable with show_entry_shortcode and last, you decode the shortcode returned in the previous statement. I don't understand how this code can work at all.

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community