Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Special Interests > Visual Media > Web Design and Development

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 13, 2006, 11:34 PM   #1
brianellisrules
macrumors regular
 
Join Date: Oct 2003
attn: php and/or javascript gurus

OK, I won't post my code right away but instead I'll start with a scenario and a question.

Let's say I have a standard link on my page:
Code:
<a href="http://www.site.com/blah.php">link</a>
Here's what I'd like to happen... the user clicks on the link. They're prompted with a dialog box. They fill out the info (one word) and then the page that loads checks that word against a stored value.

My initial thought was that the new page would have a javascript in it that would pop up a prompt box for the user. The user inputs the word and the page checks that against the stored value.

I tinkered with that for a while, but I'm pretty sure I'm running into an issue of client-size (javascript) and server-side (php). The purpose of the javascript is to get the variable from the user and the php is to check the variable and process the rest of the page (php/mysql interaction, etc). The problem arises because the javascript is getting the variable after the php has already executed (therefore returning a false value all the time).

(side note: I found some code online to transfer a variable from javascript to php and that part works.)

Is it possible to reload the page with a specific URL? Perhaps the user inputs the variable in the javascript popup, then the page reloads with the variable in the link, so the php can now process it. Something like:

http://www.site.com/blah.php?foo=variable (with ?foo=variable added via the script?)

Man, this is confusing as crap. If anyone can make any sense out of this, I'll be amazed.
brianellisrules is offline   0 Reply With Quote
Old Feb 13, 2006, 11:46 PM   #2
superbovine
macrumors 68030
 
superbovine's Avatar
 
Join Date: Nov 2003
asking google for "passing php variables to javascript". there is a lot examples on this.

the basic idea is you can generate the javascript with php therefore you can set variables upon generation of the code.
superbovine is offline   0 Reply With Quote
Old Feb 14, 2006, 02:27 AM   #3
angelneo
macrumors 68000
 
Join Date: Jun 2004
Location: afk
You can have the prompt box at the page where your link is, after processing, your javascript will open the new link. Something like this:

Code:
<script language="Javascript">
function prompt_box () {
    var yourname= prompt('Please enter your name', ' ');
    document.location.href = "http://www.site.com/blah.php?promptvalue="+yourname;
}
</script>
<a href="javascript:prompt_box()">link</a>
Although I wouldn't recommend this way as I find it quite intrusive with any pop up dialog. Why not use a text field instead?
__________________
This is good, isn't it?
angelneo is offline   0 Reply With Quote
Old Feb 14, 2006, 08:29 AM   #4
brianellisrules
Thread Starter
macrumors regular
 
Join Date: Oct 2003
Thanks for the replies!

superbovine: I never thought about keeping it in javascript, but after I read your response I though, "duh!" Thanks

angelneo: That's it, thanks! I basically want to keep people out of a certain page/area. I realize it's probably vulnerable as heck, but it should get the job done.
brianellisrules is offline   0 Reply With Quote
Old Feb 14, 2006, 12:43 PM   #5
OutThere
macrumors 601
 
OutThere's Avatar
 
Join Date: Dec 2002
Location: the good life
If you want to keep people out of a certain area, a quite secure and really easy to set up system is using .htaccess files. Almost all paid hosting services offer them, and they're really easy to set up if you have your own server. What kind of hosting do you have?

Much simpler than bungling around with php/javascript 'security' that doesn't really do anything to secure the page anyway.
__________________
puisqu'on est jeune et con, puisqu'ils sont vieux et fous. . .
OutThere is offline   0 Reply With Quote
Old Feb 14, 2006, 07:10 PM   #6
brianellisrules
Thread Starter
macrumors regular
 
Join Date: Oct 2003
Quote:
Originally Posted by OutThere
If you want to keep people out of a certain area, a quite secure and really easy to set up system is using .htaccess files. Almost all paid hosting services offer them, and they're really easy to set up if you have your own server. What kind of hosting do you have?

Much simpler than bungling around with php/javascript 'security' that doesn't really do anything to secure the page anyway.
Here's the page I'm working with: http://www.brianellisrules.com/milkshakes/

The idea is to make the update section available only to me so I have a convenient way of updating the database. Right now I'm loading the index page and using an include statement to to call the other pages.

If there's a better way to go about it, I'm all ears.

Thanks.
brianellisrules is offline   0 Reply With Quote
Old Feb 14, 2006, 07:46 PM   #7
frankblundt
macrumors 65816
 
frankblundt's Avatar
 
Join Date: Sep 2005
Location: South of the border
you can set up basic authentication on each page with a "require" using something like this:
Code:
//authenticate user

$username = "you";
$password = "your password";

if (!isset($_SERVER['PHP_AUTH_USER'])) {
	header('WWW-Authenticate: Basic realm="www.yoursite.com"');
	header('HTTP/1.0 401 Unauthorized');
	echo 'You need to be authenticated to use this page';
	exit();

} else {
	if (($_SERVER['PHP_AUTH_USER'] == $username) && ($_SERVER['PHP_AUTH_PW'] == $password)) 
	{ 
	} else {
	header('WWW-Authenticate: Basic realm="www.yoursite.com"');
	header('HTTP/1.0 401 Unauthorized');
		echo "The username and/or password you have entered is incorrect!";
		exit();
	}
}
although including the password in your webserver docs is not that great an idea.

If you don't have access to the Server's admin you can use htaccess but it's a bit clumsy (as they explain)
or if you do (for Apache at least) you can use server authentication
frankblundt is offline   0 Reply With Quote

Reply
MacRumors Forums > Special Interests > Visual Media > Web Design and Development

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
thread Thread Starter Forum Replies Last Post
question on PHP and/or Wordpress 617arg Web Design and Development 4 Jan 4, 2011 05:12 PM
PHP and MSSQL and apache (not WAMP or MAMP) tennisblues Mac OS X 3 Jul 2, 2010 05:18 PM
PHP POST arrays/Javascript validations sonofslim Web Design and Development 5 Sep 25, 2006 09:43 AM
Attn: php gurus v2 brianellisrules Web Design and Development (archive) 3 Nov 7, 2003 08:37 PM
Attn: php gurus... It's me again... brianellisrules Web Design and Development (archive) 17 Nov 7, 2003 12:45 PM


All times are GMT -5. The time now is 02:23 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

Privacy / DMCA contact / Affiliate and FTC Disclosure
Copyright 2002-2013, MacRumors.com, LLC