I have a javascript login box on my site (www.cigardig.com) that a user can click on and login on any page. The way I would like it to work is that once a user hits submit, they are redirected back to the page they logged in on. So, for example, if I login in Page 1, I want to be redirected back to Page 1 once the login is successful.

I have it implemented now; however, I've read that it's not a reliable method since some browsers and/or firewall software blocks the sending of this variable. Honestly though, I thought that since this is handled on the server not the browser that it shouldn't be blocked?

In any case, is there another way to do this that is compatible across every browser?

Did you have any difficulties with your method? If it's not broken, don't fix it.
What is "this variable"? What are you doing now in your script? Are you working with sessions or with redirects or with cookies?

The wonders of scripting, perhaps have the link be smarter, in something like

<a href='login.php'> //be something like
<a href='login.php?refer=<?php echo $_SERVER['PHP_SELF']; ?>'>

and have the login page return to the supplied parameter

Did you have any difficulties with your method? If it's not broken, don't fix it.
What is "this variable"? What are you doing now in your script? Are you working with sessions or with redirects or with cookies?

Smant,

The code is working beautifully when I test it in Safari, Chrome, Firefox, and iOS (I'm going to test in IE tomorrow). I had just read that that using this code is sometimes blocked by certain firewalls so I just trying to make the site as universally accessible as possible.

The "variable" I was reffering to was $_SERVER and I'm using sessions currently but will be implementing a cookie alternative for a persistent session.

I use below logic.
In login form place a new hidden field which will have user's current location with query parameter.

<input type='hidden' name='page' value='<?=basename($_SERVER["PHP_SELF"]).'?'.$_SERVER["QUERY_STRING"]?>' />

In php side coding use below redirection.

header('location:'$_POST['page']);

an alternative to using hidden fields is sessions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.