Page 3 of 3 FirstFirst 123
Results 21 to 24 of 24

Thread: $_GET variable not working in this case

  1. #21
    Join Date
    Dec 2009
    Posts
    29
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    hmmm. i dont understand ...

  2. #22
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    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.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #23
    Join Date
    Dec 2009
    Posts
    29
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    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");

  4. #24
    Join Date
    Dec 2009
    Posts
    29
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Using cookies

    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 Code:
    <?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 Code:
    <?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
    Code:
    setcookie($cookie,' ',1 OR time()-3600);

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •