Page 1 of 2
Now, for my next trick....
Posted: Sun Jun 22, 2003 9:38 pm
by steedvlx
as I get bolder with PhP scripting, I notice two things happening. 1) My code is starting to look like garbage, and 2) I keep creating little 'problems' that need to be solved before I can move on to bigger and better things.
My login script works pretty good, and the popup signin page looks nice IMHO, however, It must be closed manually, and the main page must be refreshed manually before the user data becomes part of the session data.
I understand that my main problem is dirty code and bad structure. But, I don't want to clean it up right now due to time constraints.
I would like to solve the problem by
1) Automatically closing the login popup window when a valid login is submitted.
and
2) Automatically refreshing the main page which called the popup in the first place.
Is this just a dream? Is it even a PhP question?
If you want to see what it looks like so far, just click the www button on this post and login as U=test P=test. The login button is on the left side menu top button(4 japanese characters on the button) The rest is still in English.
Thanks
-----------------
SteedVLX
Posted: Mon Jun 23, 2003 12:55 am
by McGruff
Many visitors get irritated by pop-ups. I know I do. Of course, good design is a very subjective thing.
You could sidestep the problem by doing it all in the same window, ending with a header call (in the form processor code which deals with the login POST vars) to re-display the original page.
Posted: Mon Jun 23, 2003 2:00 am
by steedvlx
Actually, the popup ship has already sailed from many ports on this site. To do away with them at this stage would mean a total redesign, and I'm just not up to that.
Other than the user management system, all catalog item descriptions and sub-information pages are popups.
So, can anyone tell me how to do what I need to do to auto-close on successful login and auto-refresh the main window? Seems like there should be a way.
---------------------
SteedVLX
Posted: Mon Jun 23, 2003 8:08 am
by mikusan
Assuming your popup is a script with something like login.php... then you would do what you did to get the popup in the first place... JAvascript... i dunno the scrip off top of my head that is up to you... but what you will do from php side of things is on submit you will redirect to the same script login.php?login=true and in your login.php fetch that value with $_GET and run your JavaScript...
to start you off you could use something like
Code: Select all
<BODY onLoad=window.setTimeout("window.close()",1)>
Posted: Mon Jun 23, 2003 9:22 am
by m3rajk
my guess is the page calling it has onClick="window.open('login.php', 'login', 'height=200,width-300');" or somthing like it somewere on it... well in that case you're lucky. i can help.
javascript has two different functions you'll like. make them occur on load of a successful login.
window.close(); closes the current window
window.opener() refers tot he parent window that opened this one
you should read up on them since i haven't used opener before, but i'm pretty sure since opener is to allow the subwindow to talk back to that which opened it, that it should be useful in causing the page to reload
Posted: Mon Jun 23, 2003 11:53 am
by steedvlx
Thanks! I'm going to check that out first thing tomorrow.
I'm using a script offered on microbians.com. I'll see what I can do with it based on what you've told me.
------------------
SteedVLX
Posted: Thu Jul 03, 2003 10:58 pm
by steedvlx
OK, it's taken me quite some time to get back to this, but if I understand correctly, then all I have to do is imbed the
Code: Select all
<a href="javascript:window.close()">
into my code whenever the conditions are met for closing the window; Cool! But one more problem that I cannot find a textbook answer to is... How do I properly imbed the html above into the PhP code block?
Code: Select all
<?php
if (($failure != "TRUE") AND ($failure != "SUCCESS")) {
$top_text = "Please Enter Your Member ID and Password.";}
elseif ($failure == "TRUE") {
$top_text = "Authorization Failed...Please check your Member ID and Password";
$failure = "FALSE";}
elseif ($failure == "SUCCESS") {
$top_text = "Login Sucessful!! Please close this window using the link below.";} //Here's where I want to automatically close the window and refresh the parent window.
echo "$top_text";
?>
Can anyone tell me how to do this?
-------------------
SteedVLX
Posted: Fri Jul 04, 2003 5:45 am
by steedvlx
Anybody??? Please.
-------------------
SteedVLX
Posted: Fri Jul 04, 2003 2:27 pm
by m3rajk
try changing
Code: Select all
$top_text = "Login Sucessful!! Please close this window using the link below.";} //Here's where I want to automatically close the window and refresh the parent window.
to
Code: Select all
<?php
$top_text = "Login Sucessful!! Click <a href="#" onClick="{window.opener(location.reload(true));
window.close();}">here</a> to close this window and get started in your current session";}
according to the javascript book i have, if you don't have true in location.reload() then it wont update from the server unless the headers tell it to. i know that for ie, it ignores those a lot of the time, so it's better to force it by using the boolean value of "true"
the book i have is "javascript: the definitive guide" by oreilly. mine is the 3rd edition. i think they're on the 5th edition now. the isbn for the 3rd edition is 1565923928
the isbn for the 4th or 5th or whatever they are on should be similar. that book might be handy for you. i also have their php books (both programming with and the cookbook)
NOTE: IF YOU CALL WINDOW.CLOSE() FROM THE WINDOW ITSELF YOU DO NOT NEED THE WINDOW NAME. I KNOW FROM EXPERIENCE however, it looks to me like you want multiple functions called, so you need to groupd the onClick or make a single function placed PREVIOUSLY in the html. for this purpose the javascript should PRECEED the call to it
Posted: Fri Jul 04, 2003 4:44 pm
by Judas
Hi dude.
I used this myself in a pice off code
Code: Select all
window.open('your_file','your_window_name','width=200,height=175');
Code: Select all
<?php
echo "<script language="JavaScript">";
echo "parent.your_frame_name.location=('your_file');";
echo "window.close('your_window_name');";
echo "</script>";
exit;
?>

make use of frame's
Posted: Fri Jul 04, 2003 10:29 pm
by m3rajk
this is how history channel.com does it in a pop up on their site...
Code: Select all
<html>
<head>
<STYLE TYPE="text/css">
.textSmall {color:#ffffcc; font-family:Verdana, sans-serif; font-size:7pt; text-decoration:none;}
.text {color:#ffffcc; font-family:Verdana, sans-serif; font-size:9pt; text-decoration:none;}
.textBold {color:#ffffcc; font-family:Verdana, sans-serif; font-size:9pt; font-weight:bold; text-decoration:none;}
.textBoldBig {color:#ffffcc; font-family:Verdana, sans-serif; font-size:11pt; font-weight:bold; text-decoration:none;}
</STYLE>
<script language-javascript>
<!--hide
function openParent(loc){
opener.document.location = loc;
window.close();
}
//-->
</script>
<title>Poll Results</title>
</head>
<BODY BGCOLOR="#330000" LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0" LINK="#FF9933" VLINK="#FF3333" ALINK="#FF3333">
<TABLE width="210" cellpadding="0" cellspacing="0" border="0">
<TR><TD align="center" colspan="2"><img src="images/thc_email_header.gif" border="0"></TD></TR>
<TR><td align="center" colspan="2" class="textBoldBig">This Week In History<br>Poll Results</td></tr>
<tr><td width="1" rowspan="3"><img src="/images/spacer.gif" width="1" height="350" border="0"></td>
<td class="textBold" valign="top">
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td><img src="/images/spacer.gif" width="18" height="1" border="0"></td>
<td><img src="/images/spacer.gif" width="1" height="1" border="0"></td>
<td><img src="/images/spacer.gif" width="1" height="1" border="0"></td>
</tr>
<tr>
<td width="11"><img src="/images/spacer.gif" width="11" height="1" border="0"></td>
<td class="textBold"><br>
Are the words "under God" in the Pledge of Allegiance unconstitutional? <br>
<br>
<table border="0" width="100%">
<TR>
<td><img src="/images/spacer.gif" width="75" height="1"></td>
<td><img src="/images/spacer.gif" width="15" height="1"></td>
<td><img src="/images/spacer.gif" width="50" height="1"></td>
</tr>
<tr><TD colspan="3" class="textBold"><b>Yes</b></td></tr><tr><td class="text"> 18%</td><td><IMG SRC='/images/spacer.gif' WIDTH='15' HEIGHT='1' BORDER='0'></td><td class="text">1310 votes</td></TR><tr><td colspan="3"><img src="/images/spacer.gif" height="1" width="1"></td></tr><tr><TD colspan="3" class="textBold"><b>No</b></td></tr><tr><td class="text"> 82%</td><td><IMG SRC='/images/spacer.gif' WIDTH='15' HEIGHT='1' BORDER='0'></td><td class="text">5991 votes</td></TR><tr><td colspan="3"><img src="/images/spacer.gif" height="1" width="1"></td></tr>
</table>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td colspan="3"><img src="/images/spacer.gif" width="1" height="1" border="0"></td>
</tr>
<tr>
<td><img src="/images/spacer.gif" width="1" height="1" border="0"></td>
<td align="center" class="textBold"> Total Votes: 7,301 </td>
<td><img src="/images/spacer.gif" width="1" height="1" border="0"></td>
</tr>
</table><br>
</td>
<td><img src="/images/spacer.gif" width="1" height="1" border="0"></td>
</tr>
<tr>
<td><img src="/images/spacer.gif" width="11" height="1" border="0"></td>
<td><img src="/images/spacer.gif" width="1" height="1" border="0"></td>
<td><img src="/images/spacer.gif" width="1" height="1" border="0"></td>
</tr>
<TR><td colspan="1"><img src="/images/spacer.gif" height="1" width="11"></td><td colspan="2" class="text"><a href="JavaScript: openParent('http://boards.historychannel.com/forum.jsp?forum=10');window.close();">To discuss this question in greater depth, visit our message boards!</a></td></tr>
</table>
</td>
</tr>
<tr><td> </td></tr>
<tr><td align="center" class="textBold"><a href="JavaScript:var result=window.close();">Close Window</a></td></tr>
</table>
</body>
</html>
Posted: Sat Jul 05, 2003 8:07 am
by steedvlx
Well, thank you guys very much for the input. Now, my newbie brain has top parse all of the information you've provided me. I'll let you know when I have working code.
m3rajk; thanks for the book titles. I wish PhP could do all of this stuff natively, but since it cannot, I'm going to have to order one of them thar' java books. Thanks for the ISBNs.
------------------
SteedVLX
Posted: Sat Jul 05, 2003 1:54 pm
by m3rajk
no problem. i figured that you've been using net resources till now. while they are good, sometimes it's better to have a book around to use as a resource.
if you notice, history channel has a nested javascript line that has two calls, the very ones i said to use as onclick. they just did it in a different way. and they didn't include the name of the widnow in window.close() and i can attest to it working right in both ie and mozilla (i tried it to see)
Posted: Wed Jul 23, 2003 9:57 am
by steedvlx
BTW and probably a really stupid newbie question....
How do you know and where do find the name of a window?
That would help tremendously in figuring out some of the script here. It's absolutely amazing what is NOT in these 'beginners...' books.
...
Posted: Wed Jul 23, 2003 2:16 pm
by kettle_drum
You name the windows when you open them.
window.open(url, window_name, window_properties)