SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    Internet Business Optimizer KCgame's Avatar
    Join Date
    Mar 2005
    Location
    Singapore
    Posts
    929
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Pass value using Header Command

    Hi all,
    I tried to pass a value from a page to another but it seems like the target page couldn't get the value. Is there something special i must do if i pass value via a Header command?

    PHP Code:
    header("Location: Realmdisview.php?pass=$parentid"); 
    The $parentid is equal to 4
    But the script (Realmdisview.php) is displayed without having the value
    Any help / comment is appreciated.Thanks.

  2. #2
    SitePoint Member
    Join Date
    May 2005
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am more than sure that the problem's roots lay in register_globals. You should turn it off and use $_GET['pass'] instead of trying to use $pass directly.

  3. #3
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm pretty sure this isn't a registered globals problem, Mtishetsky. Registered globals becomes an isue when displating the value of the variable, not the name of the variable itself.
    Edit:


    Unless, however, you're talking about the processing page. Then yes, it could be a registered globals problem.
    Last edited by Dylannn; May 7, 2005 at 11:44.

  4. #4
    SitePoint Guru mwolfe's Avatar
    Join Date
    Mar 2005
    Posts
    912
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmm thats funny.. i just wrote a script less than 30 minutes ago that did passed a variable thorugh header, (but it worked).. I have regsiter globals on but i always write my scripts as though they are off.. If you are not currently trying to reference the value with $_GET then i'd suggest trying it that way..

  5. #5
    SitePoint Evangelist dmsuperman's Avatar
    Join Date
    Feb 2005
    Location
    A box
    Posts
    516
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried echoing the variable to be sure that it really is 4?
    <(^.^<) \(^.^\) (^.^) (/^.^)/ (>^.^)>
    Core 2 Duo E8400 clocked @ 3.375GHz, 2x2GB 800MHz DDR2 RAM
    5x SATA drives totalling 2.5TB, 7900GS KO, 6600GT

  6. #6
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    page.php
    PHP Code:
    <?php
    $var 
    'hello';
    header("Location: page2.php?var=$var");
    exit;
    ?>
    page2.php
    PHP Code:
    <?php
    $var 
    $_GET['var'];
    echo 
    $var//should echo 'hello'
    ?>

  7. #7
    SitePoint Zealot
    Join Date
    Feb 2005
    Posts
    134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    header("Location: Realmdisview.php?pass=".$parentid);

    and get it like this:

    $pass = $_GET["pass"];

  8. #8
    Internet Business Optimizer KCgame's Avatar
    Join Date
    Mar 2005
    Location
    Singapore
    Posts
    929
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry guys, i've tried your solutions but the problem persists
    I think i'll provide a deeper explanation on my codes currently. There are two scripts that pass value to Realmdisview.php, one is using header method while the other is via

    PHP Code:
    echo"font color=#FFFF00><a href=Realmdisview.php?pass=$parentid>$list[name]</b></a>"
    The above worked fine and it displays the $parentid in Realmdisview.php and the location bar shows
    http://localhost/xampp/prog_web/Realmdisview.php?pass=4

    To mwolfe, SUPERUSER, Dylannn and dmsuperman,

    I've tried all the $_GET method but really just can't get the $parentid. While i'm doing the testing, the location bar shows
    http://localhost/xampp/prog_web/Realmdisview.php?pass=

    It seems to me that the problem is with the passing procedure via header..
    Please help :'(

  9. #9
    SitePoint Guru mwolfe's Avatar
    Join Date
    Mar 2005
    Posts
    912
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what version of php are you using? THat seems really weird because no one else has that problem.. You sure you don't have a typo somewhere.. send us the code because if the url is missing the value for parentid then most likely there is something wrong in the code.. i can't see why header would chop that off, its worked in every php version i've had from 4.1 to 5.x

  10. #10
    SitePoint Wizard Dylan B's Avatar
    Join Date
    Jul 2004
    Location
    NYC
    Posts
    1,150
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Echo $parentid.

  11. #11
    Internet Business Optimizer KCgame's Avatar
    Join Date
    Mar 2005
    Location
    Singapore
    Posts
    929
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The PHP version i'm using is 4.3.9
    I tried echo $parentid after the header redirect but it gives me

    parentid =

    I would prefer not to release the code as it also contains other parts of the program..might seem too complicated to solve this problem...
    I thank for the help that you guys have given me The worse scenario i would adopt is to give up this feature in my program

  12. #12
    SitePoint Guru Galo's Avatar
    Join Date
    May 2005
    Location
    Holland!
    Posts
    852
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by KCgame
    Sorry guys, i've tried your solutions but the problem persists
    I think i'll provide a deeper explanation on my codes currently. There are two scripts that pass value to Realmdisview.php, one is using header method while the other is via

    PHP Code:
    echo"font color=#FFFF00><a href=Realmdisview.php?pass=$parentid>$list[name]</b></a>"
    The above worked fine and it displays the $parentid in Realmdisview.php and the location bar shows
    http://localhost/xampp/prog_web/Realmdisview.php?pass=4

    To mwolfe, SUPERUSER, Dylannn and dmsuperman,

    I've tried all the $_GET method but really just can't get the $parentid. While i'm doing the testing, the location bar shows
    http://localhost/xampp/prog_web/Realmdisview.php?pass=

    It seems to me that the problem is with the passing procedure via header..
    Please help :'(

    Wach out for the way you implement this, dude ALWAYS turn of your RG for security issues and pass variables within an assoc scope WITH quotes, otherwize you could end up with double names that are allready declared as constants by PHP.


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
  •