Jump to content

What does this mean - www.example.com/index.php?a=bc


forumnz

Recommended Posts

In the script index.php, you can use

 

print $_GET['a'];

 

and you will see "bc".  That's pretty much it :)  It allows you to set variables for use in php.  The same syntax is used by forms with method=get set.

 

The full syntax is ?a=bc&c=de&f=gh

 

That will set $_GET['a'], $_GET['c'] and $_GET['f']

Link to comment
Share on other sites

mid, rid

 

These variables are made up; they are know as "pseudo" variables. You can make up any variable to add to your query string.

 

-1,orewacollege_pub:1902.

 

The letters or numbers after the equals sign is what is being queried or sent to another page, database, etc.

 

The "&" aka "ampersand" lets you add more than one variable to your query string.

 

The "+" aka "plus sign" creates a space in between characters in what ever you define your variable to be.

Link to comment
Share on other sites

They could be names of fields that are in a data table, which are within a database.

 

They also could just be variables that are within a page.

 

Example:

 

Say your domain was "http://www.greatdomain.com".

 

Say you had a page named "page1.php".

 

In "page1.php" you might have a variable know as "$mid".

 

If you type http://www.greatdomain.com/page1.php?mid=Hello

When your "page1.php" loads; where ever you had the "$mid" variable; you will now see the word "Hello"

 

This is, if you use this code:

 

<?php
print "$mid";
// you can also use "echo" instead of "print"; they have the same effect
?>

 

somewhere within "page1.php"

Link to comment
Share on other sites

So what would the mid and rid be? Names of database things?

 

they could stand for something. they names dont have to be the same as the names of things in databases. mid may mean member id and rid, well who knows. record id maybe. it can be anything you want, but usually its called something to do with what it will be used for.

Link to comment
Share on other sites

They could be names of fields that are in a data table, which are within a database.

 

They also could just be variables that are within a page.

 

Example:

 

Say your domain was "http://www.greatdomain.com".

 

Say you had a page named "page1.php".

 

In "page1.php" you might have a variable know as "$mid".

 

If you type http://www.greatdomain.com/page1.php?mid=Hello

When your "page1.php" loads; where ever you had the "$mid" variable; you will now see the word "Hello"

 

This is, if you use this code:

 

<?php
print "$mid";
// you can also use "echo" instead of "print"; they have the same effect
?>

 

somewhere within "page1.php"

You can only use $mid to get the mid variable from the url if register_globals is enabled. If this setting is not enabled then you should use $_GET['mid'] to get the mid variable (?mid=blah) from the url. But you should use $_GET regardless of the register_globals setting.

Link to comment
Share on other sites

I am running PHP Version 4.3.11 and my register_globals are enabled, yet I still can do this:

 

 

and have this code in my page

 

<?php
print "$mid";
// you can also use "echo" instead of "print"; they have the same effect
?>

 

and still send the "mid" variable's string to page1.php; where ever my code is placed in it.

 

Using "$_GET" can sometimes pose a problem because of an alert the browser gives you on page with "$_GET" in it; when page is reloaded. The alert basically tells you that the page is sending form values. So that is why I stay away from "$_GET"; except when validating.

Link to comment
Share on other sites

Well... you shouldn't use the browsers back button when you have submitted data to a site. You should provide a link/button to go back. Or tell the browser to not cache the data that is submitted to and from the site using headers.

 

Having register_globals on can create security exploits within your code allowing an attacker to take control of your site. This is the main reason why register_globals is now disabled by default as of PHP4.3 and will be removed soon be removed when PHP6 launches.

Link to comment
Share on other sites

You cannot predict what your website viewer will do. They might very well use the brower back button; it is commonly used by a majority of people, even when links are provided. If "$_GET" is suggested; it should be noted that you need to create a header to prevent page cache. Otherwise the alert will prompt; which sometimes can confuse or distress end user.

 

Having register_globals on can create security exploits within your code allowing an attacker to take control of your site. This is the main reason why register_globals is now disabled by default as of PHP4.3 and will be removed soon be removed when PHP6 launches.

 

When that day comes; then I may start using "$_GET"; until then, it works fine for me and most other people.

Link to comment
Share on other sites

What the hell are you talking about?

"Using "$_GET" can sometimes pose a problem because of an alert the browser gives you on page with "$_GET" in it; when page is reloaded."

 

I have never ever ever seen a browser alert when a page has a query string. Register globals is a security hazard, that is why it was removed. If you're having weird alerts because you're trying to use valid code, there's another problem - the rest of your code, likely.

 

Using undeclared variables is poor practice, not using $_GET, $_POST, etc is even poorer.

Link to comment
Share on other sites

Form submission alert can happen when page uses $_GET too transfer data from one page to another and the back button is used.

 

I have never ever ever seen a browser alert when a page has a query string.

 

You may need to test your pages a little better then; because I have.

 

I have never had any security problems with "register_globals" on; others might.

 

PS: Nice of you to reply to this post; although you would not reply to my message.

Link to comment
Share on other sites

Please show me an example of a page that does this.

 

PS: What message? If you are one of the many people to PM me asking me to help with your post, you might want to go read the forum rules where it says NOT to do that. That's why I didn't respond to your message. So, nice of you to read the rules before whinging.

Link to comment
Share on other sites

I do not have an example to show, because I do not use the "$_GET" method in my coding practices, but I have seen this occur in testing.

 

No ones whining - just stating the facts - a piece of coding you said would work on your sever did not work on mine. So something was not right with your code, so I sent you a message. The only reason I PM you was because you would not reply to post; must have knew it was wrong and didn't want to admit it.

Link to comment
Share on other sites

I recently used something like this while creating a link to a php file that made a new web page based on info from the db. Basically mid and rid are items found in the database. On the page the link takes you too, you would use $_GET to redefine the variable in the new page. This allows you to do a query using whatever the variable was. It basically allows you to carry over a variable into a new page.

Link to comment
Share on other sites

This is what I use to do this.

 

Say the user clicks on a link that's index.php?id=2

 

<?php


echo "<a href='test.php'>Main</a> <a href='test.php?id=2'>Other Page</a>";


$id = $_GET['id'];

//If the id is blank or it's just index.php...
if($id == "")

{

   echo "<p align='center'>Welcome to the index page.</p>";

}

//If the id is equal to "2"...
if($id == "2")

{

   echo "<p align='center'>Welcome to the other page</p>";
}
?>

 

Hope this helps.

Link to comment
Share on other sites

kenrbnsn

 

that would work or you could use a header to prevent cache also.

 

Greaser9780 and Unholy Prayer

 

that would work also.

 

But all I am saying is that, if you just want to transfer a string to another page; you can just use:

 

<?php

print "$mid";

?>

 

if there are only a few things that $mid should be able to print and not allow anything else; you could just use this above the code (i use this to validate - this is where I use $_GET):

 

<?php

// This script will redirect viewer to home page; if they type in wrong query string.

@$mid = stripslashes($_GET['mid']);

if ( strcasecmp($mid,"something") != 0 )
{
header("Location: http://www.greatdomain.com");
exit;
}

?>

 

You may not want to use this if the $mid variable string could be more then a few different things. But for only a few things that a string could be/equal; this works great.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

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

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.