Jump to content

verifying new email


jimfog

Recommended Posts

I have written a php script which prints a message to the browser every time the user confirms his new email, and the confirmation takes place after he clicks a confirmation link sent to his new email.

 

That link points to the script named verify.php.

The message is printed in verify.php, I wanted though to printed in a different page of the site and I wanted to be a modal box.

 

Meaning a redirection has to take place from verify.php to this other page(home.php).

 

What js/php code do I have to write such that after this redirection occurs the modal box appear saying "you have just confirmed your new mail".

 

 

Link to comment
Share on other sites

I'm guessing you would want Php to do this...

 

http://php.net/manual/en/function.http-redirect.php

 

...but you could also use Javascript...

 

http://www.w3schools.com/js/js_window_location.asp

The purpose here is not just redirect, but when this happens a modal box appears.

If you want to see an example of what I am trying to achieve try to change email in your twitter account(provided you have one of course).

The verification link there is ....confirm....but the page you land after clicking the link is "home" and with a modal box displayed saying "...new e-mail confirmed".

I assume redirection occurs in twitter...

Link to comment
Share on other sites

Well, which part do you not understand? Do you know how to create a modal box with the Javascript library of your choice?

I do know how to create the modal box but I do not how to make the "linkage" between PHP redirection and js code for modal box creation.

I mean this modal box will created after the redirection takes place-what kind of event is that?

So I can trigger the modal based on that event.

Link to comment
Share on other sites

Php is the one doing the verification and the redirect, so have php conditionally (by looking at a variable in the POST request) and directly add some extra javascript which will command it to create the modal onload.

Link to comment
Share on other sites

Redirect to the page and put a variable in the querystring, and use Javascript to check for that.

I have 2 questions regarding the above...since this is the approach I will use.

I want to redirect to a page named....named...profile.php?form

Meaning when form is present in the URL as above, a form appears with data regarding user profile.

I want the modal box appearing on top of that form.

If a put a variable in the query string that means that I have to rewrite all that html since it will not be GET['form'] as it is now.

 

It will be GET['form+...'].Is there any way I can avoid writing all that html?

 

How js can check for a querystring variable?Never done that before.(I found some things about it in the web but I want to hear your opinion too.)

Edited by jimfog
Link to comment
Share on other sites

I have 2 questions regarding the above...since this is the approach I will use.

I want to redirect to a page named....named...profile.php?form

Meaning when form is present in the URL as above, a form appears with data regarding user profile.

I want the modal box appearing on top of that form.

If a put a variable in the query string that means that I have to rewrite all that html since it will not be GET['form'] as it is now.

 

It will be GET['form+...'].Is there any way I can avoid writing all that html?

 

 

I found a solution to the above:

 if ((isset($_GET['form']))||(isset($_GET['formverified'])))//υπάρχουν πολλά isset get form που μάλλον πλεονάζουν              {                 if(isset($_GET['formverified']))                     {                         echo 'email confirmed';                                          }.....form HTML
Link to comment
Share on other sites

yes location.search did the job. The logic is that when location.search===querystring, then fire the modalbox(using a js library of course).

But here is the problem now. I want the above to take place once, now though it happens every time I refresh the page.

 

The aim is that the modal appears only once as in twitter.

 

What can be done here?

PHP code:

header("Location: http://localhost/Appointments/Administrator/profile.php?formverified");//redirection took place

js code:

if(location.search==='?formverified'){    $('#confirm').reveal({//the modal fires here      animation:'fade',        animationspeed:600,        closeonbackroundclick:true              });}
Link to comment
Share on other sites

Maybe set a cookie to indicate that the modal box has already been seen.

Will I do that with js?

Link to comment
Share on other sites

Uh... once you see it, can't you just clear it?

location.search = '';

...Oops -- that causes a page reload.

 

 

For a cookie...

 

http://www.w3schools.com/js/js_cookies.asp

 

...or modify the browser history...

 

https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history

Edited by davej
Link to comment
Share on other sites

Uh... once you see it, can't you just clear it?

location.search = '';

...Oops -- that causes a page reload.

 

 

For a cookie...

 

http://www.w3schools.com/js/js_cookies.asp

 

...or modify the browser history...

 

https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history

Does twitter uses a cookie too to understand if the user saw the modal box?

 

It is not necessary to answer this.

Link to comment
Share on other sites

go to twitter.com and use a browsers web inspector to view all the cookies set under that domain.

Difficult to identify which cookie(if any) is related with seeing the modal or not.

Many cookies from twitter.

Link to comment
Share on other sites

have php add it in conditionally

  <script>    function doOnLoad(){      doThis();      doThat();<?php if(isset($_SESSION['formverified']){ unset($_SESSION['formverified']); ?> //this section of code will be added ONLY if the php finds that SESSION variable $('#confirm')   .reveal({//the modal fires here          animation:'fade',          animationspeed:600,          closeonbackroundclick:true }); <?php } ?>        maybeDoThisToo();    }   </script> 

in your "form_validation.php" (or whatever you've called it) you'll set the $_SESSION variable before calling header() to redirect to the actual page. when profile.php first sees it, it'll see that theres a session variable 'formverified' and then just add some javascript to the page along with the rest of your javascript. it'll then delete the session variable so if the user refreshes, profile.php will run the check again but won't see any SESSION variable and thus skip adding in that code.

 

javascript doesn't have to mess with any cookies, in fact it's totally unaware that it's being messed with

Link to comment
Share on other sites

In the beginning your code worked as EXPECTED.Afterwards something went wrong and I cannot find what.

Here is your code:

 <script>    function doOnLoad(){ <?php if(isset($_SESSION['verified'])){       unset($_SESSION['verified']); ?>       //this section of code will be added ONLY if the php finds that SESSION variable  $('#confirmcontent').html('email confirmed');      $('#confirm').reveal({      animation:'fade',        animationspeed:600,        closeonbackroundclick:true              });<?php } ?> }    doOnLoad();  </script> 

and here is the redirection code in the php script that handles verification:

if($change=email_change_data($conn,$nonce)==true)//this function verifies the email{   $_SESSION['verified']=true;      header("Location: http://localhost/Appointments/Administrator/profile.php?formverified");//redirection takes place}

Do you see anything wrong in the above segments....cause I don't.

Link to comment
Share on other sites

Couldn't you just use Php to echo out a line to set a Javascript variable?

Can you give an example. You make it seem so easy.

Link to comment
Share on other sites

In the beginning your code worked as EXPECTED.Afterwards something went wrong and I cannot find what.

 

...

 

Do you see anything wrong in the above segments....cause I don't.

Did you remember to start the session?

 

http://www.w3schools.com/php/php_sessions.asp

 

without explicitly calling session_start(), php may attempt to auto-start a session, but may pass in the wrong session ID/Name (shouldn't happen but you never know). you could also experience a session deadlock if a certain user might access the more than once per request (once in a main page and maybe another in an iframe, or if a user has two pages open and one page is loading very slowly). php only allows one page to play with a Session variables at a time. once a page is done changing the session, run session_write_close(); which will allow other pages access to the session even if the original page using it is still loading.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...