Jump to content

Recommended Posts

Posted

I’m writing page hits to a log file and I need to know the variables that are passed along with the actual php page or the results written to log file are useless.

 

$_SERVER['PHP_SELF'] gives me the name of the file executing the script (index.php or this_page.php), but not the accompanying variables.

 

Is there a way to give me the variables passed through the url as well?

(For example: www.example.com/index.php?var=test)

I would like to get the “?var=test” information.

Posted
You either need to turn Register Globals to ON or use the $_GET[varname] to access the variables you are passing.

The problem with $_GET[varname] is that you have to know the varname you're looking for. Is there no way of actually getting the information that is in the url box on the browser?

Posted
Since you are using php check out the documentation on parse_url

Thanks for another reply.

I think that may work, but how do I actually get the url from the page I'm working on. Meaning. The url will be dynamicaly generated by what the user may select from the page before. I need to get the url that is currently being displayed.

I hope you understand what I'm asking, or am I talking in circles.

Posted

$_GET is simply an associative array containing all the variables passed through the url so you should be able to use foreach() to loop through them all.

Posted

As click said, something like this will work:

>foreach($_GET as $key=>$value){
//...
}

 

That gives you both the variable name and the value.

 

Don't forget to validate and sanitize both the data and variable names before using them.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...