Oracle apex redirect page if page item a certain value - oracle

Trying to create my own authentication since the Authentication scheme in apex won't work properly for what I am trying to do.
basically I have a function to assign the value of a PAGE ITEM either 0 or 1 and
I tried to create a branch wherein I put the above condition if the PAGE ITEM != 1
then it would redirect to another page.
the problem is the point, i tried to have it run before the header but it wont work.
Am I doing anything wrong + any solution for this.
Many Thanks!

Related

Link change SESSION var

I have a listing page for an e-commerce website with various items (item_list.php). This page is generated with a PHP loop and displays each item inside a <li> element. Every item is a link to the same page, called item_details.php .
When clicking on the link i want to run a script that changes a SESSION var to a certain $id (which will be excracted from the <li> itself with .innerHTML function) and then allowing the browser to move into the next page (item_details).
This is needed so i can display the proper information about each item.
I think this is possible with Ajax but I would prefer a solution that uses JS and PHP only.
(P.S.This is for a University project and im still a PHP newbie, i tried searching for an answer for a good while but couldn't find a solution)
No JS or other client-side code can set session values, so you need either an ajax call to php, or some workaround. This is not a complete answer, but something to get you thinking and hopefully going on the project again.
The obvious answer is just include it in the link and then get it in PHP from the $_GET -array, and filter it properly.
item title
If, however, there is some reason this is not a question with an obvious answer:
1.) Closest what you're after can be achieved with a callback and an ajax call. The idea is to have the actual link with a click function, returning false so the link doesn't fire at once, which also calls an ajax post request which finally will use document.location to redirect your browser.
I strongly advice against this, as this will prevent ctrl-clicks causing a flawed user experience.
Check out some code an examples here, which you could modify. You will also need an ajax.php file which will actually set the session value. https://developers.google.com/analytics/devguides/collection/analyticsjs/enhanced-ecommerce#product-click
2.) Now, a perhaps slightly better approach, if you truly need to do this client-side could be to use an click handler which instead of performing an ajax call or setting session directly, would be to use jQuery to set a cookie and then access this data on the item_list.php -page.
See more information and instructions here: https://www.electrictoolbox.com/jquery-cookies/
<script>
$('product_li a).click(function(){
$.cookie("li_click_data", $(this).parent().innerhtml());
return true;
});
</script>
......
<li class="product_li">your product title</li>
And in your target php file you check for the cookie. Remember, that this cookie can be set to anything, so never ever trust user data. Test and filter it in order to make sure your code is not compromised. I don't know what you want to do with this data.
$_COOKIE['li_click_data'];
3.) Finally, as the best approach, you should look at your current code, and see if there is something you can re-engineer. Here's a quick example.
You could do the following in php to save an array of the values in the session on each page load, and then get that value provided you have some kind of id or other usable identifier for your items:
// for list_items.php
foreach($item as $i) {
// Do what you normally do, but also set an array in the session.
// Presuming you have an id or some other means (here as item_id), to identify
// an item, then you can also access this array on the item_details -page.
$_SESSION['mystic_item_data_array'][$i['item_id]] = $i['thedata'];
}
// For item_details.php
$item_id = // whatever means you use to identify items, get that id.
$data_you_need = $_SESSION['mystic_item_data_array'][$item_id];
Finally.
All above ways are usable for small data like previous page, filters, keys and similar.
Basically, 1 and 2 (client-side) should only be used, if the data is actually generated client-side. If you have it in PHP already, then process it in php as well.
If your intention is to store actual html, then just regenerate that again on the other page and use one of the above ways to store the small data in case you need that.
I hope this gets you going and at least thinking of how to solve your project. Good luck!

Oracle Apex5: I get NULL from &MY_ITEM. even MY_ITEM have a value in my current Session

First of all, excuse my poor English.
I'm new to the oracle application express (Apex) and I'm kind of confused about maintaining.
I have a simple page with one item P2_ITEM1 and one button BUTTON1.
The button action is defined by dynamic action, and I defined two actions:
Execute PL/SQL with the following
APEX_UTIL.SET_SESSION_STATE('P2_ITEM1',:P2_ITEM1);
Alert to show the value of &P2_ITEM1.
What I'm expecting to see is an alert with the value of P2_ITEM1 that I have entered, but I always get null.
Here is a snapshot of the page design and page run.
Here I'm expecting to have the value 123 but it's always NULL UNLESS I submit the page.
Thanks in advance.
The &P2_ITEM1 is a substitution variable which is estimated after the page opened. in your case you just need to use JavaScript as alert $v('P2_ITEM1').
Are you using &P2_ITEM1. , dot in last?

Problems with custom routing and child paths

I'm working on a short url application and I'm running into a problem with child paths. Essentially what this does is save shortened URLs to a database which then translates into the full path when called by the user.
The user will typically call the short URL by typing
http://companyServer/{shortUrlName}
which will be translated on the back end as
http://companyServer/SomePath/ChildPath1/....
The MVC application allows users to create their own short URLs and has two ActionResults to administer this (CreateShorty & ViewShortys).
The end result should be that the user should be able to type in the following URLs and be redirected correctly.
http://companyServer/{actionName}
http://companyServer/{shortUrlName}
http://companyServer/{shortUrlName}?{optionalParameters}
http://companyServer/{shortUrlName}/{childUrlPath}
http://companyServer/{shortUrlName}/{childUrlPath}?{optionalParameters}
The problem I'm having is that I can do all except for the last two. If I attempt to add child parameters the first rout to be hit when viewing an action like create or view is
http://companyServer/{actionName}
it then goes on to hit
http://companyServer/{shortUrlName}/{childUrlPath} which blocks me getting to my action methods.
Any help in this would be appreciated as I'm rather new to MVC.

Using WebGrid with sortable columns, the call to the controller bypasses the Session

In ASP.NET MVC 4, I have a multipage app that does some security checking on the first page, stores the results in a Session variable, then uses OnActionExecuting on every Controller to test the Session variable as I move from page to page. One of the views uses a WebGrid with sortable columns. When I click on the column header to engage the sort, I get a call to the view's default Action, but, in OnActionExecuting, the Session variable is not there. It appears to have created a new session. My logic then treats it as a security failure.
I have not yet found where this click (to sort) is being handled, so that's my first issue - perhaps I could influence what is being passed in. Alternatively, (and ideally), there is a setting in WebGrid that I have missed that would maintain the current Session. I am away from the code at the moment, but those are the things I haven't found yet.
What I am looking for is a way to preserve the Session while using the WebGrid sortable column feature.
Additional Information: In the view, the WebGrid's <th> elements are all anchors, like <a href="/MyController?sort=MyColumnName?sortdir=ASC">
(I could use a better answer, but this worked for me)
Since the value in the heading is actually an anchor, I was able to discover that the QUERY_STRING always contains "sort=". Thus, I could at least check for this and restore the missing security variable to the Session, based on the assumption that, if I am getting this query string, the user has passed the security test before.
(filterContext.RequestContext.HttpContext.Request.Params["QUERY_STRING"].Contains("sort="))
I'm still thinking that WebGrid should not be starting a new session for me, but at least this workaround will get me going.
NOTE FOR FUTURE REFERENCE: We were using the <system.web> setting <sessionState cookieless="true">. Apparently, when WebGrid sets up its links for sorting, it does not detect that setting, thus it does not include the session id in the URL. This is why WebGrid was starting a new session for us.

CodeIgniter Pagination is not working with routing

I want to show all users page wise initially. So if I browse http://mydomain/user it will redirect to http://mydomain/user/page/1 and so on. But if I browse http://mydomain/user/1 it will show only single user with id of user.
http://mydomain/user/1 >> it works fine. But as I want pagination so I want to redirect http://mydomain/user to http://mydomain/user/page/1 always
My Routing Info is:
$route['user/(:num)'] = 'user/index/$1';
$route['user'] = 'user/page/$1';
But when I pressed to http://mydomain/user it does not rout to user/page/$1. I have index() method which output to single user information if I give slug. so get a page wise list I used routing and page method. But it is not working. it gives 404 Page not found
Could anybody have solution please..
I think you need to look at the manual for routing:
http://ellislab.com/codeigniter/user-guide/general/routing.html
As far as i can see your second route doesn´t make much sense, you are calling the method page() of your User class - and trying to pass in $1 which does not exist. I think you need to explain better what you want to achieve with your second route - I don´t really see why you need it at all at the moment.

Resources