php ajax redirect

php ajax redirect

am 27.11.2007 15:37:09 von ampeloso

Hello,
I have a Login page that checks a Db for a Un and Pw using ajax.
If the Login is incorrect, they just get a embedded message.
If it is correct, I want to redirect COMPLETLY.
Whats happening is the new page is being embedded into the login page,
and I dont want that.
.............................
if ($rowcount==0){
echo "

Wrong Username or Password Dufus

";
}
else
{//echo "

Your logged in $result_1[U]

";
$_SESSION['U'] = $result_1[U];
$_SESSION['P'] = $result_1[P];
header( 'Location: Main_Mockup.php' );
}
................................

Any suggestions for this
Thanks
Mike

Re: php ajax redirect

am 27.11.2007 15:47:06 von Captain Paralytic

On 27 Nov, 14:37, Mike wrote:
> Hello,
> I have a Login page that checks a Db for a Un and Pw using ajax.
> If the Login is incorrect, they just get a embedded message.
> If it is correct, I want to redirect COMPLETLY.
> Whats happening is the new page is being embedded into the login page,
> and I dont want that.
> ............................
> if ($rowcount==0){
> echo "

Wrong Username or Password Dufus

";}
>
> else
> {//echo "

Your logged in $result_1[U]

";
> $_SESSION['U'] = $result_1[U];
> $_SESSION['P'] = $result_1[P];
> header( 'Location: Main_Mockup.php' );}
>
> ...............................
>
> Any suggestions for this
> Thanks
> Mike

I think that "Your logged in" should possibly be "You're logged in".

Now for your initial question, it depends on what you are doing on the
client with this returned data. Are you in a frame? Maybe you could
use the href object?

Re: php ajax redirect

am 27.11.2007 16:01:46 von ampeloso

On Nov 27, 9:47 am, Captain Paralytic wrote:
> On 27 Nov, 14:37, Mike wrote:
>
>
>
>
>
> > Hello,
> > I have a Login page that checks a Db for a Un and Pw using ajax.
> > If the Login is incorrect, they just get a embedded message.
> > If it is correct, I want to redirect COMPLETLY.
> > Whats happening is the new page is being embedded into the login page,
> > and I dont want that.
> > ............................
> > if ($rowcount==0){
> > echo "

Wrong Username or Password Dufus

";}
>
> > else
> > {//echo "

Your logged in $result_1[U]

";
> > $_SESSION['U'] = $result_1[U];
> > $_SESSION['P'] = $result_1[P];
> > header( 'Location: Main_Mockup.php' );}
>
> > ...............................
>
> > Any suggestions for this
> > Thanks
> > Mike
>
> I think that "Your logged in" should possibly be "You're logged in".
>
> Now for your initial question, it depends on what you are doing on the
> client with this returned data. Are you in a frame? Maybe you could
> use the href object?- Hide quoted text -
>
> - Show quoted text -

Thank,:)
I dont proofread till the end
I am not in a frame (yuk).
I just want to redirect out to a new page and keep my _session
Variables (Which it does anyway).
I'm pretty good with php, but new at AJAX.
Thanks,
Mike

Re: php ajax redirect

am 27.11.2007 16:23:47 von Captain Paralytic

On 27 Nov, 15:01, Mike wrote:
> On Nov 27, 9:47 am, Captain Paralytic wrote:
>
>
>
> > On 27 Nov, 14:37, Mike wrote:
>
> > > Hello,
> > > I have a Login page that checks a Db for a Un and Pw using ajax.
> > > If the Login is incorrect, they just get a embedded message.
> > > If it is correct, I want to redirect COMPLETLY.
> > > Whats happening is the new page is being embedded into the login page,
> > > and I dont want that.
> > > ............................
> > > if ($rowcount==0){
> > > echo "

Wrong Username or Password Dufus

";}
>
> > > else
> > > {//echo "

Your logged in $result_1[U]

";
> > > $_SESSION['U'] = $result_1[U];
> > > $_SESSION['P'] = $result_1[P];
> > > header( 'Location: Main_Mockup.php' );}
>
> > > ...............................
>
> > > Any suggestions for this
> > > Thanks
> > > Mike
>
> > I think that "Your logged in" should possibly be "You're logged in".
>
> > Now for your initial question, it depends on what you are doing on the
> > client with this returned data. Are you in a frame? Maybe you could
> > use the href object?- Hide quoted text -
>
> > - Show quoted text -
>
> Thank,:)
> I dont proofread till the end
> I am not in a frame (yuk).
> I just want to redirect out to a new page and keep my _session
> Variables (Which it does anyway).
> I'm pretty good with php, but new at AJAX.
> Thanks,
> Mike

What I was trying to point out is that you have shown us nothing about
what you are doing on the client, so it is dificult to advise what you
should do differently.

Re: php ajax redirect

am 27.11.2007 16:26:00 von Good Man

Mike wrote in news:57b383e9-bcbb-4332-98b2-
943467baca8c@x69g2000hsx.googlegroups.com:

> On Nov 27, 9:47 am, Captain Paralytic wrote:
>> On 27 Nov, 14:37, Mike wrote:
>>
>>
>>
>>
>>
>> > Hello,
>> > I have a Login page that checks a Db for a Un and Pw using ajax.
>> > If the Login is incorrect, they just get a embedded message.
>> > If it is correct, I want to redirect COMPLETLY.
>> > Whats happening is the new page is being embedded into the login
page,
>> > and I dont want that.
>> > ............................
>> > if ($rowcount==0){
>> > echo "

Wrong Username or Password Dufus

";}
>>
>> > else
>> > {//echo "

Your logged in $result_1[U]

";
>> > $_SESSION['U'] = $result_1[U];
>> > $_SESSION['P'] = $result_1[P];
>> > header( 'Location: Main_Mockup.php' );}
>>
>> > ...............................
>>
>> > Any suggestions for this
>> > Thanks
>> > Mike
>>
>> I think that "Your logged in" should possibly be "You're logged in".
>>
>> Now for your initial question, it depends on what you are doing on
the
>> client with this returned data. Are you in a frame? Maybe you could
>> use the href object?- Hide quoted text -
>>
>> - Show quoted text -
>
> Thank,:)
> I dont proofread till the end
> I am not in a frame (yuk).
> I just want to redirect out to a new page and keep my _session
> Variables (Which it does anyway).
> I'm pretty good with php, but new at AJAX.
> Thanks,
> Mike

You're going to have to get pretty familiar with javascript.
Essentially this is a javascript question. You get a result BACK from a
PHP script, and then use javascript to put your result into action.

Perhaps AJAX and login pages don't go together too well - I know in my
apps, I've elected to use a complete form submission.

Re: php ajax redirect

am 27.11.2007 18:14:43 von luiheidsgoeroe

On Tue, 27 Nov 2007 16:01:46 +0100, Mike wrote:
> On Nov 27, 9:47 am, Captain Paralytic wrote:
>> On 27 Nov, 14:37, Mike wrote:
>> > I have a Login page that checks a Db for a Un and Pw using ajax.
>> > If the Login is incorrect, they just get a embedded message.
>> > If it is correct, I want to redirect COMPLETLY.
>> > Whats happening is the new page is being embedded into the login pa=
ge,
>> > and I dont want that.
>> > ............................
>> > if ($rowcount==0){
>> > echo "

Wrong Username or Password Dufus

";}
>>
>> > else
>> > {//echo "

Your logged in $result_1[U]

";
>> > $_SESSION['U'] =3D $result_1[U];
>> > $_SESSION['P'] =3D $result_1[P];
>> > header( 'Location: Main_Mockup.php' );}
>>
>> > ...............................
>>
>> Now for your initial question, it depends on what you are doing on th=
e
>> client with this returned data. Are you in a frame? Maybe you could
>> use the href object?
>
> I dont proofread till the end
> I am not in a frame (yuk).
> I just want to redirect out to a new page and keep my _session
> Variables (Which it does anyway).
> I'm pretty good with php, but new at AJAX.

If you're getting the output with an javascript request, sending redirec=
t =

headers won't help you changing the current page (most HTTP headers are =
=

useless). It can redirect javascript, so in this case the javascript =

request will indeed be redirected to an entire page, and as long as you =
=

have configured javascript to write the output of the request to the =

current document...

Common practise is to return a (JSON) object that holds the 'action to b=
e =

performed', which is interpreted by the javascript asking for a response=
=

to begin with. Wether it is to add content, alter form elements, or do a=
=

location.replace on the window, all is possible as long as javascript =

understands your output. How to do this reliably is better asked in =

comp.lang.javascript.
-- =

Rik Wasmus

Re: php ajax redirect

am 27.11.2007 18:52:35 von Toby A Inkster

Mike wrote:

> If the Login is incorrect, they just get a embedded message.
> If it is correct, I want to redirect COMPLETLY.

if ($rowcount==0)
{
echo "

Wrong Username or Password Dufus

";
}
else
{
$_SESSION['U'] = $result_1[U];
$_SESSION['P'] = $result_1[P];
print 'Location: Main_Mockup.php';
}

And then your Javascript needs to do something like this:

var $result = (result from AJAX request as string);
if ($result.match( /^Location\:/i ))
{
var $url = $result.replace( /^Location\:\s+/i, '' );
window.location.href = $url;
}
else
{
// Display the message like you already do.
}

The redirection is the Javascript's job here, not PHP's. The PHP just
needs to tell the Javascript where to redirect to.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 3 days, 34 min.]

It'll be in the Last Place You Look
http://tobyinkster.co.uk/blog/2007/11/21/no2id/

Re: php ajax redirect

am 27.11.2007 21:25:46 von ampeloso

On Nov 27, 12:52 pm, Toby A Inkster
wrote:
> Mike wrote:
> > If the Login is incorrect, they just get a embedded message.
> > If it is correct, I want to redirect COMPLETLY.
>
> if ($rowcount==0)
> {
> echo "

Wrong Username or Password Dufus

";
> }
> else
> {
> $_SESSION['U'] = $result_1[U];
> $_SESSION['P'] = $result_1[P];
> print 'Location: Main_Mockup.php';
> }
>
> And then your Javascript needs to do something like this:
>
> var $result = (result from AJAX request as string);
> if ($result.match( /^Location\:/i ))
> {
> var $url = $result.replace( /^Location\:\s+/i, '' );
> window.location.href = $url;
> }
> else
> {
> // Display the message like you already do.
> }
>
> The redirection is the Javascript's job here, not PHP's. The PHP just
> needs to tell the Javascript where to redirect to.
>
> --
> Toby A Inkster BSc (Hons) ARCS
> [Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
> [OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 3 days, 34 min.]
>
> It'll be in the Last Place You Look
> http://tobyinkster.co.uk/blog/2007/11/21/no2id/

Actually I did get it to work with this:(which of course is just
Javascript)
if (xmlHttp.readyState==4)
{
if (xmlHttp.responseText == "

Wrong Username or Password Dufus p>")
{
document.getElementById("txtHint").innerHTML=xmlHttp.respons eText
}
else window.location = "http://www.ampsoft.com/NCAA/Main_Mockup.php"
}
}

Thanks
Mike

Re: php ajax redirect

am 28.11.2007 03:58:14 von Good Man

Mike wrote in
news:9accba9e-42d8-450d-b893-c1776f7b3a83@s8g2000prg.googleg roups.com:

> Actually I did get it to work with this:(which of course is just
> Javascript)
> if (xmlHttp.readyState==4)
> {
> if (xmlHttp.responseText == "

Wrong Username or Password Dufus > p>")
> {
> document.getElementById("txtHint").innerHTML=xmlHttp.respons eText
> }
> else window.location = "http://www.ampsoft.com/NCAA/Main_Mockup.php"
> }
> }
>

Just be sure you're using PHP sessions on
http://www.ampsoft.com/NCAA/Main_Mockup.php, otherwise all someone has to
do is look at your javascript code for instant admission to your restricted
area / pages.