Log in

View Full Version : http://localhost/test.htm?user=



hmsnacker123
04-14-2008, 02:35 PM
hi, i have a problem:

firstly how do i get the address bar to say this
http://localhost/test.htm?user=

i would like this to be submitted via a form and then depending on what the username puts it will display

Nile
04-14-2008, 09:49 PM
Well, what you could so is you have some javascript like this:


var ext = document.url.split('?');
var exte = document.url.split('=');

Then use a str.

Rockonmetal
04-14-2008, 10:33 PM
if you wanna go easier than Javascript... php has got a easy line of code which is litterally one line to get the variable and its contents! Amazing right?
to do that... first do this:

<form action="test.htm" method="GET"></form>
IF your using php to get the information... you do this:

<?php
$_GET['user'];//the name of the text input goes where 'user' is...
$_GET['pass'];
$_GET['otherstuff'];
?>But lets say you have multiple inputs or you want to make a permanent link example below
<a href="example.com/index.php?user=dank&othervariable=Iforgotmypassword&example=example">See dank's profile</a>
make sure to put on index.php (or what ever the target page with the variables in the url) has the $_GET...
For extra variables add an & sign between the variable content and the next variable.
The variables cannot be over 100 characters long...
Its really easy and a really cool line of code in php... most user-content driven websites use url get methods to data...
THOUGH! I would not recommend transfering passwords using this...
Hopes this helps!

Nile
04-14-2008, 10:57 PM
He can't use PHP, he needs javascript.
Here this should do it for you:

<html>
<head>
<title>Please type your na...</title>
</head>
<body>
<body onLoad="get_url()">

<script type="text/javascript">
function get_url(){
var find = "name=";
var im_url = document.URL;
var find_m = im_url.search(find);
var full_u = im_url.substr(find_m+find.length);
document.getElementById('welcome').innerHTML=full_u;
}
</script>
<form action="" method="get">
<input type="text" name="name" />
<input type="submit" value="Enter!" />
</form>
<div id="welcome"></div>
</body>
</html>

BYK
04-15-2008, 08:51 AM
var pageVars;

function fillPageVars()
{
pageVars=undefined;
pageVars=(document.location.search.length>1) ? document.location.search.substring(1).split('&') : new Array(0);
for (var i=0; i<pageVars.length; i++)
{
tempArray=pageVars[i].split('=');
pageVars[tempArray[0]]=decodeURIComponent(tempArray[1]);
delete tempArray;
}
}

The above script fills all the parameters to the pageVars variable just like PHP's $_GET variable.

Nile
04-15-2008, 11:35 AM
@BYK Yours doesn't answer his question.

hmsnacker123
04-15-2008, 11:48 AM
I cant use php because my apache does not support it please can you / anyone give a tutorial on how to set up php on apache. thanks :)

Nile
04-15-2008, 11:50 AM
Your getting off topic, try the codes and see whats best for you :D.

Medyman
04-15-2008, 01:19 PM
Your getting off topic, try the codes and see whats best for you :D.


I cant use php because my apache does not support it please can you / anyone give a tutorial on how to set up php on apache. thanks :)

LOL. Nile seems adamant about his code working for you. You might want to try it out and let him know how it goes :D

But if you still want to install PHP, here is a general tutorial (http://www.php-mysql-tutorial.com/install-apache-php-mysql.php). Installing PHP is probably the smarter way to go. You'll quickly run into limitations in this kind of application with Javascript (not to mention the potential accessibility issues).

hmsnacker123
04-15-2008, 02:48 PM
Thanks, Nile Your JavaScript Worked. :)

BYK
04-15-2008, 03:39 PM
@BYK Yours doesn't answer his question.

It is a code which is open to all kinds of query variables, and yours was only for "name". So I think it answers(I wouldn't have posted it if I didn't think so :)), BUT only for this purpose yours had worked ;)

hmsnacker123
04-15-2008, 06:03 PM
_________________________________
1 More Question Guys:

I Have Set Up Custom Errors On My Apache;

And When, Say A 404 Error Occurs, I Want It To Redirect To default.htm (main page) and in the address bar to say http://localhost/default.htm?errorpath=404

and because it has the error path of 404 i want an alert, or something to write in the document, because it has the address:

http://localhost/default.htm?errorpath=404

Medyman
04-15-2008, 06:32 PM
_________________________________
1 More Question Guys:

I Have Set Up Custom Errors On My Apache;

And When, Say A 404 Error Occurs, I Want It To Redirect To default.htm (main page) and in the address bar to say http://localhost/default.htm?errorpath=404

and because it has the error path of 404 i want an alert, or something to write in the document, because it has the address:

http://localhost/default.htm?errorpath=404


Is there a reason you're doing it that way? It seems more complicated than it has to be.

Anyway,
You can use .htaccess to redirect to custom error pages.

Instructions: http://www.thesitewizard.com/archive/custom404.shtml

BYK
04-15-2008, 06:32 PM
I think you really should use PHP :)

If you have your own server you can use those LAMP or WAMP packages which include Apache, PHP and MySQL.

If you are on a Linux machine BitNami packages would be very easy for you to install.

hmsnacker123
04-15-2008, 06:57 PM
i have already set up the custom error url (http://localhost/default.htm?errorpath=404);

and i would rather do it this way. please help.

BYK
04-15-2008, 07:27 PM
Allright, then now you should use the code I gave a few posts ago which Nile did not liked :D

Then you can call it on body's onload event and shape your page according to the pageVars['errorpath'] variable's value ;)

hmsnacker123
04-15-2008, 07:31 PM
is there any html associated with it?

and how would i edit the content of http://localhost/default.htm?errorpath=404


please right fully instead of multiple posts cos i have to go v. soon

and it cant be tempary because i need all the 404 errors to point to it.

hmsnacker123
04-15-2008, 09:03 PM
C'Mon plz!