PDA

View Full Version : $_GET variable not working in this case



legend.raju
12-29-2009, 09:04 PM
i have a dynamically loaded page with the following



Main Page
{

Menu

Dynamically loaded content having form
{

display $_GET['someid'];

Form
{

action = index.php#currentpage
}

}

}



this is not working....

when i goto that seperate page

something/currentpage.php?user=adfsfd&id=234234

i want to work like this

something.index.php?user=adkjs&id=234#currentpage

how is this possible

bluewalrus
12-29-2009, 09:07 PM
Can you post your actual code?

legend.raju
12-29-2009, 09:34 PM
it is in prodigy.zxq.net

check the members page at

Members.php is


<div class="pagecontent">
<h3>
<?php
if($_GET['userid'] == "boopathi")
{
if($_GET['password'] == "admin")
{
echo "Welcome" + $_GET['userid'];
}
}
else
{
echo "Login";
}
?>

</h3>
<form name="login_form" action="#members" method="get">
<table border=0 cellpadding=1 cellspacing=8>
<tr>
<td>User name </td>
<td><input type="text" class="box" name="userid" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" class="box" name="password" /></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" />
</td>
</tr>
</table>
</form>

</div>


and

index.php has
members.php as a dynamically loaded ajax page

the site is

http://prodigy.zxq.net

.....

i understand that it has error in action=index.php#members ....
but what i want is

the members.php is loaded into a div
when i submit the form it should validate in members.php or some other file other than index.php and return to the same page ....

ll be helpful if it is dynamic .. if the page reloads also no problem ..

do you understand what i want to do ?

Schmoopy
12-30-2009, 07:28 AM
The error is being caused because you are assuming that $_GET['userid'] is already set, where it may not be. Change it to:



<?php
if(isset($_GET['userid']) && $_GET['userid'] == "boopathi")
{
if(isset($_GET['password']) && $_GET['password'] == "admin")
{
echo "Welcome " . $_GET['userid'];
}
}
else
{
echo "Login";
}
?>


I also changed the "Welcome" part, as you want to concatenate the strings, and not actually add the two together.

legend.raju
12-30-2009, 05:16 PM
what about action="#members" .....
i tried with the changes (isset) ...
but not working ...

the form is submitted .. but not working .. !

bluewalrus
12-30-2009, 05:38 PM
Might be cause of the anchor link not sure if this goes back to the server try ?members instead of #members

legend.raju
12-30-2009, 06:12 PM
it is not working ... !

i want something thats happening dynamically as in new orkut
orkut.com/Main#home?uid=24233424

but for me the url gets changed to this
something/?userid=something&passwd=abcd#members

bluewalrus
12-30-2009, 07:19 PM
Use post not get to keep the values out of the address bar


or with schmoopys code


<div class="pagecontent">
<h3>
<?php
if(isset($_POST['userid']) && $_POST['userid'] == "boopathi")
{
if(isset($_POST['password']) && $_POST['password'] == "admin")
{
echo "Welcome " . $_POST['userid'];
}
}
else
{
echo "Login";
}
?>
</h3>
<form name="login_form" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<table border=0 cellpadding=1 cellspacing=8>
<tr>
<td>User name </td>
<td><input type="text" class="box" name="userid" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" class="box" name="password" /></td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" />
</td>
</tr>
</table>
</form>

</div>

legend.raju
12-30-2009, 08:52 PM
Post variable not working too .. .!

and schmoopys code :

it is the same as action="members.php"

i go to members.php instead of index.php#members .. !

bluewalrus
12-30-2009, 09:13 PM
the posts are probably working but code is wrong forgot you were on different page change <?php echo $_SERVER['PHP_SELF'];?> to "#" or "?".

legend.raju
12-30-2009, 11:33 PM
both of them not working ..
can u tell me how new orkut works ..
everything is dynamic over there .. !

my case is similar to orkut scrapbook ... now . .!

legend.raju
12-31-2009, 01:02 AM
check gmail standard version address bar

http://mail.google.com/mail/?shva=1#inbox

similar to what i get
something/?username=abcd#members
if i use the GET variable ....

they too have a ajax page loaded dynamically in the right ... !

bluewalrus
12-31-2009, 01:17 AM
Yea google and orkut work together. They use and ajax. Trying to explaing everything they have going on would take a while if you just want the address bar to look like that make the form action to "?userid=<?php echo $userid; ?>#home" you'd have to use a sql statment to get the id though and validate the login.

alphonse.tan
12-31-2009, 03:52 AM
Yea google and orkut work together. They use and ajax. Trying to explaing everything they have going on would take a while if you just want the address bar to look like that make the form action to "?userid=<?php echo $userid; ?>#home" you'd have to use a sql statment to get the id though and validate the login.

doing this.. it would be better to use $_REQUEST['userid'];

bluewalrus
12-31-2009, 04:06 AM
The variables in $_REQUEST are provided to the script via the GET, POST, and COOKIE input mechanisms and therefore could be modified by the remote user and cannot be trusted.

How is REQUEST better?

djr33
12-31-2009, 07:43 AM
$_REQUEST holds the values of GET, POST and COOKIE, so it is more general and will work regardless of how a variable is sent: for example, if you don't know whether a value will be send in the url or by a form with method="post", or maybe even in a cookie, then that will hold all of them and you don't need to worry about it.

However, using $_REQUEST is lazy and bad practice if you know the variable will only becoming from one source. It's like a lesser version of register_globals, though at least it doesn't end up conflicting with anything else in the script.

legend.raju
12-31-2009, 08:07 AM
whatever variable passing it is , in the child page it is not working
i tried this

action="?user=<?php echo $userid; ?>#members"

when i use the $_get/post/request var in members.php it is not working
BUT when i use it in the main index.php it is working ......
.........

djr33
12-31-2009, 08:27 AM
Is that the action of a form? You can use get variables as the action only if the form itself is set to method="post", so that the values do not conflict.
action="?ex=ample" would remove that when submitted if the method="get".

legend.raju
12-31-2009, 08:33 AM
yeah .. i dint use like that ...

even when directly using address bar , navigating to

something/?user=abcd#members
doesnt work

....

is it a problem that the entire page "members.php" is included as innerHTML ...

djr33
12-31-2009, 08:51 AM
Then that is not part of the request, so it won't be available in the php. Sorry if I'm not helping-- I jumped in this halfway.

legend.raju
12-31-2009, 08:56 AM
hmmm. i dont understand ...

djr33
12-31-2009, 09:09 AM
If you load a page: http://example.com?var=value

Then on THAT page, $_GET['var'] will be "value".

But then if you AFTER THAT load another page with javascript, you cannot access the data from the first load.

If you use a function "load" to make part of the page load:
load('otherpage.php');
Then it will load the same page like if you typed "otherpage.php" into the address bar.
If you did:
load('otherpage.php?var=value');
Only then, $_GET['var'] will be "value" in the included page.

When you use ajax or another method like that, it is the same as loading the page a different time than the first load-- the same variables will not be available.


Based on this and the other questions you have posted, I think you might be trying to do more than is possible with ajax, so you might want to use iframes instead. That would be easier to control and more reliable.

legend.raju
12-31-2009, 07:35 PM
hmm... yes .. ! but i changed

before :
{
<a href="" onclick=calls javascript>
javascript replaces addressbar text to address#page
}

now : {
<a href=#page onclick=javascript
javascript loads ajax page
}


then too not working .. !

i tried with setting cookies ... ! then it worked in the way i expected .. !
but when i goto validate.php it is not returning back to original page "index.php#members"

used header("Location: index.php#members");

legend.raju
12-31-2009, 08:37 PM
im able to get what i need using cookies ... it works fine .. but have a little problem deleting the cookies

here is the code

members.php :

<?php
if(isset($_COOKIE['prodigyValidationResult']))
{
$username = $_COOKIE['prodigyValidationResult'];
$r = true;
}
else
{
$r = false;
}
?>
<?php
if($r){
echo "Welcome " . $username;
}else{
echo "Login";
}
?>
</h3>

<?php
if($r){
echo "<br />Login correct";
echo '
<a href="javascript:document.logout.submit()">Logout</a>
<form action="validate.php" method="post" name="logout">
<input type="hidden" name="log" value="1" />
</form>
';
}else{
echo '<form name="login_form" action="validate.php" method="post">
<table border=0 cellpadding=1 cellspacing=8>
<tr>
<td>User name </td>
<td><input type="text" class="box" name="userid" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" class="box" name="passwd" /></td>
</tr>
<tr>
<td></td>
<td>
<input type="hidden" name="log" value="0" />
<input type="submit" />
</td>
</tr>
</table>
</form>';
}
?>

validation.php :

<?php

$cookie = "prodigyValidationResult";

if($_POST['log'] == "0")
{
if($_POST['userid'] == "boopathirajaa" )
{
if($_POST['passwd'] == "admin" )
{
if(isset($_COOKIE[$cookie]) == false)
{
setcookie($cookie,$_POST['userid'],time()+3600,'/');
echo "Login done";
}
else
{
echo "Already logged in as " . $_COOKIE[$cookie] . ". Logging in as " . $_POST['userid'] . "?<br>";
setcookie($cookie,'',time()-3600);
setcookie($cookie,$_POST['userid'],time() + 3600,'/');
echo "Login done";

}
}
}
}
else if($_POST['log'] == "1")
{
echo "Logging out <br />";
echo setcookie($cookie,"",1);
}

?>
<a href="index.php#members" onclick="document.validation.submit();">Click here to go back</a>



im not able to delete the cookie i set using

setcookie($cookie,' ',1 OR time()-3600);