How to redirect user in bootstrap after confirmation in Zend Framework? - redirect

I'm just new to Zend Framework. Currently what I'm trying to do is when user access my website
they will first see a select box with two language such as english and germany to choose.
Only when they make a selection, the browser will redirect them to the index controller of that specific language page.
So my question is how to make a select box in bootstrap file or any kind of possible ways to do that and how to redirect user after that? Any solution will be much appreciated!

Don't ever use bootstrap file (and I'm talking about both Bootstrap.php and index.php) for this kind of operations. First, it just won't work the way you ask; second, you'll mess your app's structure big time.
Instead you may use one of the following approaches:
1) add some predispatch hook that will check whether the choice has already been made by checking the user's cookies. If it is, proceed with request as usual (probably setting some Zend_Registry lang variable to be used later), if not, redirect for the language choosing page; the latter should store the choice made in cookies.
2) implement a simple rule in your Router/mod_rewrite: when the requested URL contains 'the language part' (http://example.com/lang/xx/... or just http://example.com/xx/...), it automatically uses this part so set the lang param. If not, the request is automatically redirected to the language choosing page. The latter, in turn, leads the user to a language-specific page, where all the links are made language-specific.
The latter approach is inferior, in my opinion, as user will have to use a language-tuned gateway all the time. But you don't have to store this info in cookies.

You could make a plugin that use the preDispatch event to look if the language has been chosen (e.g stored in cookie or session) and redirect to the landing page if not.
Look here zend framework plug-in - predispatch()
and the ZF's action plugin documentation.
That's what I do to force login in my app.
Now in your position what I would really do would be detecting the language of the user with a fallback to English and a switch widget somewhere in your navbar.

Related

Is it possible to create a MVC application that navigates like Facebook?

Facebook seems to have a single page where the content changes based on user interaction.
For example: If I click on somebody's post, the url changes to the user's profile/posts/.
Now I'm sure this is possible to implement on MVC.
Can somebody help me get started?
Perhaps some reference/sameple/tutorial (I believe this will heavily involve configuring the routings).
Sure, that's called Custom Routing. You can set up custom routing in the routeconfig.cs file in your project (for pre-MVC4, routing is in Gloabal.asax). Then you just use an Actionlink Helper to build your links.
Read More: http://www.codeproject.com/Articles/641783/Customizing-Routes-in-ASP-NET-MVC

Java based FB.init

Is there a way to process the FB.init function within plain java code ?
I have added an inline frame based up, that sends a signed_request param to my server.
The signed_request already covers a good bunch of information.
Due to the fact, that the session_key and the secret are required, I have to display the Facebook login button and let the user click it in order to set the fbs_ cookie.
Any idea how to get completely rid of the login button ?
Java is a server-side programming language, while JavaScript is client-side. Therefore, if you intend to use the FB JavaScript library, you need to embed this in your webpage. This is pretty straightforward with frameworks like Wicket for instance. However, no matter you embed the JavaScript at server side, it'll get executed when it gets downloaded and invoked in the user's browser.

Why is my application's authentication page different to everyone else's?

As per the Authentication Documentation, I'm directing my user's to the following URL to initiate the authentication flow:
https://www.facebook.com/dialog/oauth?client_id=251747341532139&redirect_uri=https://www.facebook.com/connect/login_success.html
However, instead of the login page looking like:
... (i.e. like it does in the documentation and in other Apps I've created and used), it looks like this...
Does anyone know why?
I've tracked the redirects that the page makes, and it's as follows:
https://www.facebook.com/dialog/oauth?client_id=251747341532139&redirect_uri=https://www.facebook.com/connect/login_success.html
https://www.facebook.com/connect/uiserver.php?app_id=251747341532139&method=permissions.request&display=page&next=https://www.facebook.com/connect/login_success.html&response_type=code&fbconnect=1
https://www.facebook.com/login.php?api_key=251747341532139&skip_api_login=1&display=page&cancel_url=https://www.facebook.com/connect/login_success.html?error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request.&fbconnect=1&next=https://www.facebook.com/connect/uiserver.php?method=permissions.request&app_id=251747341532139&display=page&redirect_uri=https%253A%252F%252Fwww.facebook.com%252Fconnect%252Flogin_success.html&response_type=code&fbconnect=1&from_login=1&rcount=1
Application type is set to Native/Desktop, and I've set the App Integration to "Website".
If the language I'm using makes any difference, I'm using C#, and setting the Url of System.Windows.Form.WebBrowser.
As per the above comments, you can use the display parameter in the URL to control which kind of dialog to show, as you would normally do with the JS SDK.
Your URL becomes:
https://www.facebook.com/dialog/oauth?client_id=xx&redirect_uri=yy&display=popup

How would I find what page a user comes from?

I am looking for a way to detect which page a user comes from (the users referring page). If the user does not come from a page called "index.php", they should be redirected to a page, like, google.com. Any programming language that can be embedded into an html file. Thanks!
you can get the previouse url by :
$_SERVER['HTTP_REFERER']
in some cases this can be forbidden by the browser user settings
'HTTP_REFERER' The address of the page (if any) which referred the
user agent to the current page. This is set by the user agent. Not all
user agents will set this, and some provide the ability to modify
HTTP_REFERER as a feature. In short, it cannot really be trusted.
check it on the php manual
http://php.net/manual/en/reserved.variables.server.php
Look at the HTTP Referer header field?
You can use the HTTP referrer header: http://en.wikipedia.org/wiki/HTTP_referrer
There's a tutorial here on how to access it using javascript.
You would use the header called Referer [sic] . See: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html (section 14.36)
Obtain its value however you want.

Best way to store data for Greasemonkey based crawler?

I want to crawl a site with Greasemonkey and wonder if there is a better way to temporarily store values than with GM_setValue.
What I want to do is crawl my contacts in a social network and extract the Twitter URLs from their profile pages.
My current plan is to open each profile in it's own tab, so that it looks more like a normal browsing person (ie css, scrits and images will be loaded by the browser). Then store the Twitter URL with GM_setValue. Once all profile pages have been crawled, create a page using the stored values.
I am not so happy with the storage option, though. Maybe there is a better way?
I have considered inserting the user profiles into the current page so that I could all process them with the same script instance, but I am not sure if XMLHttpRequest looks indistignuishable from normal user initiated requests.
I've had a similar project where I needed to get a whole lot of (invoice line data) from a website, and export it into an accounting database.
You could create a .aspx (or PHP etc) back end, which processes POST data and stores it in a database.
Any data you want from a single page can be stored in a form (hidden using style properties if you want), using field names or id's to identify the data. Then all you need to do is make the form action an .aspx page and submit the form using javascript.
(Alternatively you could add a submit button to the page, allowing you to check the form values before submitting to the database).
I think you should first ask yourself why you want to use Greasemonkey for your particular problem. Greasemonkey was developed as a way to modify one's browsing experience -- not as a web spider. While you might be able to get Greasemonkey to do this using GM_setValue, I think you will find your solution to be kludgy and hard to develop. That, and it will require many manual steps (like opening all of those tabs, clearing the Greasemonkey variables between runs of your script, etc).
Does anything you are doing require the JavaScript on the page to be executed? If so, you may want to consider using Perl and WWW::Mechanize::Plugin::JavaScript. Otherwise, I would recommend that you do all of this in a simple Python script. You will want to take a look at the urllib2 module. For example, take a look at the following code (note that it uses cookielib to support cookies, which you will most likely need if your script requires you to be logged into a site):
import urllib2
import cookielib
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookielib.CookieJar()))
response = opener.open("http://twitter.com/someguy")
responseText = response.read()
Then you can do all of the processing you want using regular expressions.
Have you considered Google Gears? That would give you access to a local SQLite database which you can store large amounts of information in.
The reason for wanting Greasemonkey
is that the page to be crawled does
not really approve of robots.
Greasemonkey seemed like the easiest
way to make the crawler look
legitimate.
Actually tainting your crawler through the browser does not make it that more legitimate. You are still breaking the terms of use of the site! WWW::Mechanize for example is equally well suited to 'spoof' your User Agent String, but that and crawling is, if the site does not allow spiders/crawlers, illegal!
The reason for wanting Greasemonkey is that the page to be crawled does not really approve of robots. Greasemonkey seemed like the easiest way to make the crawler look legitimate.
I think this is the the hardest way imaginable to make a crawler look legitimate. Spoofing a web browser is trivially easy with some basic understanding of HTTP headers.
Also, some sites have heuristics that look for clients that behave like spiders, so simply making requests look like browser doesn't mean the won't know what you are doing.