I have been programming in PHP with globals enabled since around 2005. I have started to develop on a more professional scale now, and with security at stake, I need to make the change.

Trouble is, I haven't been able to find a tutorial that answers my questions regarding globals (or lack there of) and don't want to have to resort to modifying the php.ini files.

Consider the following:

<form method="post" action="testing.php">

This is the format I used to program in. The tutorials I have all read advised the new 'action' format is now "$_self" or something, and are not be linked to an external php file.

Does this mean that all scripts w/out globals enabled must be sent to the same page?

If this is not actually the case, and it is just a big coincidence, consider the following:

include 'phpconfig.php';

 $db = mysql_connect("localhost", $theusername, $thepassword);
  mysql_select_db($prefix . "_remixconfig",$db);
  $sql="SELECT * FROM images";
  $result=mysql_query($sql,$db);

  while ($row = mysql_fetch_array($result))
  {
    $id = $row["id"];
    $path = $row["path"];

    echo"The file path is: $path. Click <a href=\"delete.php?id=$id\">here</a> to delete.";
  }

This is the format showing how I'd usually handle mysql calls.
This code in particular is supposed to call the $row["id"] and $row["path"] feilds, and create a link to delete.php and carry the 'id' variable over.

I used to just be able to call '$id' on delete.php, how easy was that!? This no longer works.

Tutorials I have read, mainly using form posts as their examples, advise of using the function $_POST or $_GET (depending on what method one used) or $_REQUEST as a wild card in terms of type of data send method.

But what I can't seem to figure out is what one would use when following a link? My scripts keep bugging out.

Finaly, if I have the globals enabled in various folders on my webserver, will this new 'anti-global-variable' method of programming still work?

Thanks for your help!

Recommended Answers

All 8 Replies

$_GET will get the variable from the URL. And yes, that will still work when you have the globals enabled.

Member Avatar for rajarajan2017

Yes, _Self execute the page from the current locaiton itself. you dont even need to create any other file to get your variable to another page. Instead we can write in a same file.

$_GET get the value from the query string (from url) and method="get" used in the caller file.

Yes, _Self execute the page from the current locaiton itself. you dont even need to create any other file to get your variable to another page. Instead we can write in a same file.

$_GET get the value from the query string (from url) and method="get" used in the caller file.

I THINK I understand what you are saying, but what do I do if I WANT to place my php commands in a different file? Is this possible w/out the use of globals?

See, there will be more operations than just to delete the said image (see my example code above); I don't want to have, for example, a delete query, an alter query and a create query all on the same page. The program will be untidy and hard to navigate. I know I could probably send a variable through the form to $_self and 'include' the pages, but for my information, is it really no longer possible to send information to a new page through a form/link?

Member Avatar for rajarajan2017

If you are going to maintain the php commands in different file, and create a form tag with the method post or get. Then retrieve the values in another page by using $POST or $GET and process the php command with the fetched value.

If you are going to maintain the php commands in different file, and create a form tag with the method post or get. Then retrieve the values in another page by using $POST or $GET and process the php command with the fetched value.

OK, so is a form always required then? Can I not send variables through a link anymore? Because I tried 'delete.php?quid=3' and then tried to echo $GET but the variable would not echo anything.

(Thanks for your help here by the way!)

Member Avatar for rajarajan2017

Yes, but give also a try for $request

Yes, but give also a try for $request

Wow, awfully sorry, it appears that I have a caching issue, and $_get works just fine. I've never seen this before on a PHP document, but it seems to have cached a version with an error. I wasn't getting any echo's returned when I was echoing the ID variable when 'delete.php?id=4'. I was refreshing, ctrl+refreshing, and STILL getting the same result. I ended up changing the file completely, and realized that even then it remained the same! As soon as I tried 'delete.php?id=5' it was all there!

Thanks so much!

PS. I figure it'll be a caching issue on my home server. Until fixed i'll be using an anonymous proxy server to view. ;) Cheers.

(Directed @ Genevish) haha.. I wish I had read that reply earlier, thanks man, must have scrolled right past it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.