php for keypad password with images - php

im trying to use a mix of html and php to allow a webpage to have a keypad like what you find on card readers and security locks. this will redirect to the html page for people to access the page inside. i am using html redirects at the moment so
<a href="file location on server">
<img src="keypad1" alt="" width="42" height="42" border="0">
</a>
there has to be a way that i can use php to listen for the click of a button and then wait for the next one without saying correct or wrong code until the # key is pressed. after each key is pressed at this moment intime the code redirects to another page and waits for the next key. if its wrong it loads the same page until the # is pressed which is just programmed to return to another page saying error. and starts the password process again. i dont want people to just hit f12 and find out the code thats why im thinking of php if the code could be external from the websites html code. no one will have the intelligence to work out where the code is if its not in front of them. any suggestions on ways?

PHP is a scripting language and executes at server side only. The result you are getting on your browser is mixer of HTML, CSS and JavaScript based on what you have used with that page.
PHP will never know what is happening on browser unless and until you inform server every time anything happens on browser. For example clicks, mouse movement, focus, blur, keypress, keyup, all these are events that can be tracked using JavaScript.
As you are trying to develop security program that should looks like card readers keypad(http://www.govgroup.com/images_products/2407014_big.jpg), right? You can track every button press with JavaScript unless # button pressed. You can use jQuery for quick & easy implementation.
You can store every button click in JavaScript variable and when # key pressed you can send entire code to php for validation and if code is correct you can redirect to success page or else if code failed you can show the same keypad log in page again with error message.
Please check below example for how to listen to button clicks and how to store values. This is just an example, you can extend the logic to your need.
var buttons_pressed="";
jQuery('ul li').click(function(){
if(jQuery(this).text() === '#'){
alert(buttons_pressed);
buttons_pressed="";
}else{
buttons_pressed += jQuery(this).text();
}
})
See # JSFiddle

Related

I want to click on link and not go to other html page but echo a page. Is that posible in php

How can I use php to echo a page instead of linking to existing html page with hyperlink?
One example would be
<html>
<body>
click on this link to go back
</body>
</html>
Now, I don't want this link above to be a link to html page but to echo a page with php code when user clicks on click on this link to go back(to generate a page). This way, nobody can access a page after they logout.
Can php do this?
If someone logged out of your website or application I assume you will have a check whether or not this person is allowed to view the content.
Your question itself is very unclear to me. But it sound a bit if you want to do client-side coding (don't follow a link when it's clicked) with PHP which is not possible since PHP is a server side language. You will need Javascript to change the behavior of a link (for example, make an AJAX request which returns the content of another page).
Create a function, what the function should do is it should get triggered on a button click event and the code inside the function must send an curl request to the url you want and get back the html from it and echo it on your page
For answering the second part of your question!. you want no one to access the data without logging in so maintain $_SERVER['']; and sessions for users and validate if the user is inside a genuine session then show him content else no

hide url in navigation bar

I have different pages and scripts on my website. I want to show 1 URL in the adressbar for all the pages.
I have pages like:
www.example.com/index.php
www.example.com/map1/index.php
www.example.com/map1/map2/index.php
www.example.com/map1/map2/map3/index.php
I want that all these URLS should be shown like:
www.example.com
I have expirimented with my .htaccess script, but I cant get this working.
Can anybody help me with this problem? How can I show all the URL`s on my page like "www.example.com".
You could make www.example.com/index.php (which would be the default for www.example.com) be the only page that actually gets loaded fully, with all the others simply providing content to be loaded via ajax.
You could also make www.example.com/index.php contain only an iFrame or a frameset, such that clicks to other locations would only be to the nested frame, leaving the address bar always at www.example.com
You could also try taking "map1" and "map2" etc out of the URL and use them instead as post variables, or $_SESSION variables, or what have you.
Hide the Target URL of a Link in Status Bar
There are some instances where you have redirect the user through one page to get them to another page. There is a way to do this stealthily - without letting the user know that there was a redirect. Yes - it sounds evil - but it don't have to be. Say you have a click tracking software - you have to track each click the users make. To do that you need a redirecting page what will track the clicks. Hopefully, the following illustration will make things clearer...
Current Page->Page with the click counter->Destination Page
You don't want the user to see that you are passing through the middle page. Usually, the URL will flash in the address bar for just a second(or less) - so we don't have to worry about that. We just have to prevent the URL from appearing in the status bar when the user hovers over the link.
There are three methods to do this...
Change the status text
Hijack and stop the click event and redirect
page.
Make an Ajax call on click event.
Changing Status Text
This is the old method. This uses the window.status property to show a different URL to the user. Simple and easy method - but it rarely works now a days. This method has been abused by malicious sites a lot - so most browsers have disable this option. In Firefox, you can find that option at Tools -> Preferences -> Content -> Enable Javascript(click on the 'Advanced' Button) -> Change status bar text. If that's checked, you can use window.status to change the status bar text. But its disabled by default.
But if you still want to use this method(not recommended), this is how to do it...
<a href="click_counter.php?redirect_to=http://www.google.com/"
onmouseover="window.status='http://www.google.com/';return true;"
onmouseout="window.status='';">Go To Google</a>
Hijacking Click Event
In this method, when the user clicks on the link, the script captures the click event and stops it. This will prevent the browser from opening up the target page. Then we use location.href to go to the new page. Sample code below...
HTML Code
Go To Google
Javascript Code
<script type="text/javascript">
function init() {
document.getElementById("google-link").onclick=function(e) {
e=e||window.event;
stopEvent(e);
location.href="click_counter.php?redirect_to=http://www.google.com/";
return false;
}
}
window.onload=init;
</script>
Ajax Method
This is for all you web 2.0 fans. Ajax method simply makes a call to the counter server side script on the click event. This is perhaps the best method of all - as the counter URL doesn't appear at all. Needless to say, the server side script used here will be different from the one used in the other methods - there is no redirection here. The code is very simple as well...
HTML Code
Go To Google
**Javascript Code**
<script type="text/javascript">
function init() {
document.getElementById("google-link").onclick=function(e) {
jx("counter.php?url="+escape("http://www.google.com/")); //Use your favorite ajax library here.
}
}
window.onload=init;
</script>

Laravel's flash data available after browser back button clicked [duplicate]

So the SMEs at my current place of employment want to try and disable the back button for certain pages. We have a page where the user makes some selections and submits them to be processed. In some instances they have to enter a comment on another page.
What the users have figured out is that they don't have to enter a comment if they submit the information and go to the page with the comment and then hit the back button to return to the previous page.
I know there are several different solutions to this (and many of them are far more elegant then disabling the back button), but this is what I'm left with. Is it possible to prevent someone from going back to the previous page through altering the behavior of the back button. (like a submit -> return false sorta thing).
Due to double posting information I can't have it return to the previous page and then move to the current one. I can only have it not direct away from the current page. I Googled it, but I only saw posts saying that it will always return to the previous page. I was hoping that someone has some mad kung foo js skills that can make this possible.
I understand that everyone says this is a bad idea, and I agree, but sometimes you just have to do what you're told.
Don't do this, just don't. It's bad interface design and forces the user's browser to behave in a way that they don't expect.
I would regard any script that successfully stopped my back button from working to be a hack, and I would expect the IE team to release a security-fix for it.
The back button is part of their program interface, not your website.
In your specific case I think the best bet is to add an unload event to the page that warns the user if they haven't completed the form. The back button would be unaffected and the user would be warned of their action.
Nah, you're doomed. Even if you pop the page up in some different browser and hid the back button, there's always the Backspace key.
The problem with marketing guys and analyst types is that some of them do not understand the fundamental concept of the web being stateless. They do not understand that the page is totally, totally unaware of the browser using it and absolute control of the browser is totally outside the capability of web pages.
The best way to discourage your users to hit the back button is to make sure that your page loses all its data when they press back, e.g., the comment page is the only point where the data can be saved, and if they do press the back button they have to do everything all over again (think along the lines of pragma: nocache).
Users will complain, sure, but they are the reason that this godforsaken requirement exists, right?
I've seen this before:
window.onBack = history.forward();
It is most definitely a dirty hack and, if at all possible, I would attempt to not disable the back button. And the user can probably still get around it quite easily. And depending on caching, there is no telling if the server code will be processed or if the cached page with JavaScript will run first.
So, yeah, use at your own risk :)
I came up with a little hack that disables the back button using JavaScript. I checked it on chrome 10, firefox 3.6 and IE9:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<title>Untitled Page</title>
<script type = "text/javascript" >
function changeHashOnLoad() {
window.location.href += "#";
setTimeout("changeHashAgain()", "50");
}
function changeHashAgain() {
window.location.href += "1";
}
// If you want to skip the auto-positioning at the top of browser window,you can add the below code:
window.location.hash=' ';
var storedHash = window.location.hash;
window.setInterval(function () {
if (window.location.hash != storedHash) {
window.location.hash = storedHash;
}
}, 50);
</script>
</head>
<body onload="changeHashOnLoad(); ">
Try to hit the back button!
</body>
</html>
Do you have access to the server-side source code? If so, you can put a check on the first page that redirects to the second page if the information has been submitted already (you'll need to use sessions for this, obviously). At a former job, this is how we handled multi-step applications (application as in application for acceptance).
Could you move the comment to the previous page and make it a required field there?
Disabling the back button will not work.
Because of the security isolation of javascript in the browser, you cannot change what the back button does.
Perhaps you could store something in the user's session that indicates that a comment is needed, and have any page in the app that the user tries to load redirect to the comment page?
What if the user closes their browser when he/she gets tot he comment page?
I know that you have not been given a choice here, but since what they are asking for seems to be impossible...
Perhaps you could just not consider the item as completed until the user enters comments. Thus, you would need to keep track of both in-progress items and completed items, and make that distinction in the UI, but this might be the most robust method.
Or just put the comment field on the form page?
What the users have figured out is
that they don't have to enter a
comment if they submit the information
and go to the page with the comment
and then hit the back button to return
to the previous page.
Then they are probably also smart enough to type 'no comment' into the comments field.
You can try to force people to add comments, but you will probably just end up with bad unusable software, annoyed users, and still not get comments. This is usually a good time to take a step back and reconsider what you are doing from the users' point of view.
Disabling the back button seems kind of a "brute force" approach.
Another option would be that you could jump out to a modal dialog that doesn't have command buttons, walk users through the workflow, and close the dialog when the process is complete.
You should secure your application against double submission instead of breaking user interface to hide the bug.
There simply is no reliable way to do this. You cannot guarantee that 100% of the time you can stop the user from doing this.
With that in mind, is it worth going to extremely exotic solutions to disable "most" of the time? That's for you to decide.
Good luck.
AS a simple solution: try this one. Insert an update panel and a button in there and use javascript to hide it and then press it on page load. Yes I understand that it will cause your page to post back on load and may not work if javascript is disabled but certainly will help you achieve a half decent response to the back button issue. Andy
You can prevent them from going back to the previous page. location.replace() replaces the current page's history entry with a new page, so...
page1.html: user clicks a link that goes to page2.html
page2.html: user clicks a link that calls location.replace('page3.html');
page3.html: user clicks back button and goes to page1.html
This may not fit well with doing a POST, but you could post the data to a web service via AJAX, then call location.replace()
If you are starting a new web app from scratch, or you have enough time to rework your app, you can use JavaScript and AJAX to avoid the browser's history, back, and forward functions.
Open your app in a new window, either before or immediately after login.
If you wish, use window options to hide the nav bar (with the back and forward buttons).
Use AJAX for all server requests, without ever changing the window's location URL.
Use a simple web API to get data and perform actions, and render the app using JavaScript.
There will be only one URL in the window's history.
The back and forward buttons will do nothing.
The window can be closed automatically on logging out.
No information is leaked to the browser history, which can help with security.
This technique answers the question, but it also contradicts best practice in several ways:
The back and forward buttons should behave as expected.
An app should not open new browser windows.
An app should still function without JavaScript.
Please carefully consider your requirements and your users before using this technique.
I don't see this solution :
function removeBack(){
window.location.hash="nbb";
window.location.hash="";
window.onhashchange=function(){window.location.hash="";}
}

Echo out text on previous page after link?

Basically i have a favorite icon on the users profile page. Another user can press this button and it will link to favorites.php where it will carry out the sql query to add that user to the database.
This then leaves the user stuck on favorites.php faced with a blank page. What i want favorites.php to do is after its processed the query is echo out a piece of text that says user added to favorites on the previous page profile.php. but i can't simply redirect them to profile.php using header because each user profile has an id extension like profile.php?id=13 and they will have clicked on that users profile.
so my question is can i use a header to redirect to the previous page they was on (url specific) so that its that users id they was originally onwith that corresponding . can this be done?
Thanks
This sort of UI interaction is typically accomplished with AJAX calls these days.
When the user clicks on the favorite icon, a bit of javascript on that page would call favorites.php in the background. Favorites.php would then issue the SQL call and return a bit of json (using json_encode()) to tell your Javascript code whether or not the SQL was successful. Your javascript would then react and update the UI accordingly.
jQuery is a very common way to accomplish this, so I'd suggest a quick google for "jquery ajax tutorial".
If you absolutely must support browsers which don't have javascript, the alternative would be for favorites.php to look at the referer:
<?php
//do important stuff here
http_redirect($_SERVER['HTTP_REFERER']);
?>
However, php's manual indicates that HTTP_REFERER is not reliable, so you still may end up with errors. Ajax for the win.

Is there really no way to programmatically click a link using PHP?

I have been trying for a while now trying to figure out how to programmatically click a link using PHP and/or javascript. I have it setup so if the user clicks a link it will refresh a table. You don't really need to know why I want to do this b/c then it will go down a whole long road of confusion. Just know that there is a link to be clicked and I really really want to programmatically click that link using PHP and/or javascript.
Is there really no way to do this?
Edit: The code where I need to put the auto-click is in PHP, which would have to create and trigger some javascript or jquery or whatever.
Edit 2: Ok, now that you're all confused ... the real problem is that I have a Drupal form that has a property set to use AJAX when submitting. So the submission is done using the jquery plugin that is a module for Drupal. The AJAX setting is just an attribute setting and I do not have access to the underlying code that goes along with the submission of the form. Which forces me to have to refresh the table after the button is clicked. I really wish I could just attach the refreshing to the button click event for the submit of the form. But since I don't have access to that code I don't believe it's possible.
With Javascript, you can since it runs on the client machine, where the link exists. But the link doesn't even exist when PHP is doing it's magic, so you cannot click it "with" PHP. Keep in mind that PHP runs on the server, but the link exists only on the client.
Click a link with Javascript is rather simple:
// Index Page
document.getElementById("mylink").click();
Make sure all of your values are spelled properly. You can even output this command from PHP:
<?php print "<script type='text/javascript'>
document.getElementById('myLink').click();
</script>"; ?>
</body>
</html>
Note I placed this just before the closing </body> tag to ensure the link is present on the page.
Since it is drupal i assume that the form you're speaking of has an URL and therefore you could inject javascript code with the following module: JS Injector

Categories