1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Register Globals

Discussion in 'Web Design & Development' started by brez, Nov 10, 2007.

Thread Status:
Not open for further replies.
Advertisement
  1. brez

    brez Thread Starter

    Joined:
    Aug 19, 2007
    Messages:
    106
    I have a php script that i want to use but, it needs register globals to enable it to function properly.

    Just wondering if its possible to re-write it so i can use it without RG.
     
  2. MMJ

    MMJ Guest

    Joined:
    Oct 15, 2006
    Messages:
    3,625
    Heres a code snippet I wrote a while back for one of my scripts:

    PHP:
    <?php
    foreach ($_POST as $index => $value) {
        $
    $index $value;
    }
    ?>
    This will emulate register globals for the data sent via POST, not GET. If you need it for GET just make another loop and replace $_POST with $_GET.

    There might be a better way to do this though.
     
  3. brez

    brez Thread Starter

    Joined:
    Aug 19, 2007
    Messages:
    106
    Thanks, would that code have to go onto the top of every page of the script?

    Like so....
    .....................................................
    <?
    if(define("breztech", false)) die("SORRY 404");
    <?php
    foreach ($_POST as $index => $value) {
    $$index = $value;
    }
    ?>

    if($_POST['sssubmit']) {
    $query=mysql_query("select * from cl_options where 1 order by 'opt' asc");
    while($ht=mysql_fetch_array($query)) {
    eval("\$".$ht[opt]."=\$_POST['".$ht[opt]."'];");
    eval("\$".$ht[opt]."=kiemtra(1,\$".$ht[opt].",0,0,250,\"Options must not have special characters !\",0);");

    eval("\$q=mysql_query(\"update cl_options set vl='\$".$ht[opt]."' where opt='".$ht[opt]."' \")or die(\"Error in \$".$ht[opt]." <-- ".$ht[opt]."\");");
     
  4. MMJ

    MMJ Guest

    Joined:
    Oct 15, 2006
    Messages:
    3,625
    yeah, remove <?php and ?> though.
     
  5. brez

    brez Thread Starter

    Joined:
    Aug 19, 2007
    Messages:
    106
    Ok,
    Many thanks for the assistance.
     
  6. brez

    brez Thread Starter

    Joined:
    Aug 19, 2007
    Messages:
    106
    Yep it works alright.

    had to create the second loop (GET) for 7 pages of the script.

    Again thanks!
     
  7. MMJ

    MMJ Guest

    Joined:
    Oct 15, 2006
    Messages:
    3,625
    no problem, glad I could help.
     
  8. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/650234

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice