I recently started building a login system using php and mysql database.
Right now I have already built this using php code and data typed by user in a bootstrap modal.
User opens his mailbox, click a link which executes verification script in database to set user as verified and load my main site page.
After that I would like to add some modal to tell something like "Your account was verified" just once. What is a right way to do it? I thought that it can be done by php by running jquery function located in index.php like
<?php
header('location:index.php');
echo "<script> $('#addText').modal();</script>";
?>
But as I can see it is not correct and php just loads index.php and that's all.
P.S. I am sorry for my ignorance of php fundamentals.
If you use an HTTP redirect, the contents of the page are ignored.
Instead, you can use a meta-refresh tag, which allows delaying the redirect.
<head>
<meta http-equiv="refresh" content="5;url=https://example.com/index.php" />
<script src="js/jquery.js">
<script> $(function() {$('#addText').modal();})</script>
</head>
5; means to delay the refresh for 5 seconds.
Related
I currently have the code below (PHP)
<?php
require_once __DIR__.'/includes/Connect.php';
require_once __DIR__.'/includes/Nojs.php';
require_once __DIR__.'/includes/Main.php';
require_once __DIR__.'/includes/footer.php';
?>
I want Main.php to load only if JavaScript is enabled, and Nojs.php to load only is JavaScript is disabled.
Surrounding Nojs.php with tags does nothing (See below code)
<?php
require_once __DIR__.'/includes/Connect.php';
?>
<noscript>
<?php
require_once __DIR__.'/includes/Nojs.php';
?>
</noscript>
<?php
require_once __DIR__.'/includes/Main.php';
require_once __DIR__.'/includes/footer.php';
?>
Since I know the PHP cannot access the browser as it is done server-side, is it possible to try to use HTML (Like I attempted) or other JavaScript to get it to work?
Thanks in advance.
EDIT:
Creating a new file for nojs.php and using meta refresh works, but there is a noticeable delay. The page starts loading the original URL and then redirects to the other. A visitor can quite easily cancel the page load process and stop the page load before the redirect. They will have a partly loaded page, but all the content they really need will be there. Is there a way to force an immediate redirect (Yes, "content" is set to "0" per the below anwser)?
Create another PHP file with no js version when first PHP loaded it will check if no js support will redirect to no js version of PHP
<noscript>
<meta http-equiv="refresh" content="0;url=nojs-version.php">
</noscript>
Edit: It is also mentioned by W3C as technique without confusing user
https://www.w3.org/TR/WCAG20-TECHS/H76.html
I have a PHP file which deals with registration on a site, currently once the user has registered they are redirected to the home page and a success message states that the user's registration has been successful.
I would like to change this to a jquery notification.
Is it possible for me to include jquery within this registration PHP file?
For example.
<script type="text/javascript" src="js/jquery_v_1.4.js"></script>
<script type="text/javascript" src="js/jquery_notification_v.1.js"></script>
If I place this at the top of the page before the PHP tags commence.
If this is not possible, what is the best way to overcome this obstacle?
Thank you
Yes that is fine, as long as they are outside of the <?php ?> tags
Yes you can do it. just be careful not to put any javascript/html (any output, not even space) code before header or session_start functions, cause these will cause problems if anything is printed before they run.
i'm using this code to load a php page inside a html page using javascipt , but it doesn't work. the code is below :
<html>
....
<div id="home" style="background: #000;background-image: none;height:100%;"></div>
<script>
$('#home').load('http://www.website.com/file/index.php').trigger("create");
</script>
</html>
the php file exists and works fine but it doesn't show up in the actual page . If you have modification i can make i'll be thankful
If you remote website is not in same server you can't do it, for same-origin policy security restrictions, as specified in the load() documentation.
But, you will have a proxy script like:
proxyScript.php
<?php echo file_get_contents("http://www.website.com/file/index.php"); ?>
And, now, you can: $('#home').load('proxyScripts.php').trigger("create");
Or you will configure your remote server to accept remote request, read: How to use Cross domain Ajax request
I think it has something to do with javascript happening AFTER php happens.
Why not switch it with
include('http://www.website.com/file/index.php');
if your hiding that div you could just use javascript to show / hide the div based on what ever happens. Dont try to lead the php file when its hovered or clicked or w/e. Load it first and just display it with js.
is there a way to make a redirection from inside a phtml file in ZF2 Framework?
The reason is that I am using the jQuery $.POST mechanism (ajax) to refresh a part of the page, but I cannot make a redirection from the controller used by the ajax because it will load the new page into the div (which is inside another page).
I have tried using ZF2's :
$this->_redirect($this->url('restaurants'));
But I get a ServiceNotFoundException. I also tried php's:
<?php header( 'Location: http://www.yoursite.com/new_page.html' ) ; ?>
But this just did not work at all.
Hope this is clear enough!.. Any help is much appreciated!
You can't use header when you printed anything before it. There must not be any output before header. So this means the exact same for $this->_redirect().
What you could do is the following:
Add this to your head section
<meta http-equiv="refresh" content="0; url=http://example.com/">
or use javascript to redirect the user. If you don't want to extend your layout file you should use javascript:
<script type="text/javascript">
window.location = "http://www.example.com/"
</script>
EDIT
After rereading your question i think the only possible way for you to redirect the user after you've received the page content is the javascript solution.
I am looking for fast methods/ways I can redirect a HTML page to another page.
Currently I use meta-tags to redirect a HTML page to a python script that grabs the website HTML from a SQL database(grabs different HTML based on whether user is on a Mobile device) then sends that HTML back. But this is visibly slow, it shows a blank white page(redirect HTML page) then shows the python script page.
I know that its not the python script thats slow because if I just go straight to the python script(no redirect from the HTML page) then it loads very fast & with no white screen.
So for example; someone accesses http://mywebsite.com/contactUs.html which contains only the following HTML:
<HTML> <HEAD><META HTTP-EQUIV=Refresh CONTENT="0; url=cgi-bin/loadWebPage.py?webpage=50002"> </HEAD> </HTML>
<!-- This redirects to my python script that grabs the contact us HTML & prints it out(shows the webpage HTML) -->
Are there other ways a HTML file can redirect to a python script that will be faster?
Maybe I can use HTTP messages? Would the following text/code work in a HTML file?:
Status: 301 Moved"
Location:/cgi-bin/loadWebPage.py?webpage=50002
Would my last resort be AJAX or javascript to get the fastest result?
<html>
<head>
<script type="text/javascript">
<!--
window.location = 'http://mywebsite.com/cgi-bin/loadWebpage.py?webPage=50001';
-->
</script>
</head>
<body>
</body>
</html>
Place a file called .htaccess in the same directory as your HTML file. If the file is called "http://www.example.com/foo/bar.html" then .htaccess would contain:
Redirect permanent /foo/bar.html http://www.example.com/script.py
Note that the file that gets redirected does not have http://www.example.com, while the file you redirect it to needs the full URL.
If it's your own server, it's a little faster to disable .htaccess files, while instead putting the Redirect command in your httpd.conf file.
Don Quixote is correct about the .htaccess, I would just like to point out that
http://progtuts.info/198/the-anatomy-of-a-htaccess-file-hints-and-tips/
Will provide some examples and a whole lot of stuff on how to edit your htaccess files etc.
Redirect will definitely work.