Jump to content

[SOLVED] Simple php GET code


mmitdnn

Recommended Posts

Hi guys,

 

I want to be able to parse variables from the url into the content of a php page.

 

For example:

 

site.com/page.php?myvariable=something

 

I'm currently using a very simple code (that I don't even remember) - something like: <?"myvariable"?>.

 

This code does work on some servers but not on all.

 

I want a more "stable" code. Something that will work on all servers no matter what php version they run. And I need something to show even if for some reason the php variable is absent.

 

I'm not a php programmer (in case you haven't figured it out already :-)).

 

I've been told that the string may need to have GET as well as "if else" and "echo".

 

Could someone please tell me what code I could use?

 

Thanks...

Link to comment
https://forums.phpfreaks.com/topic/48602-solved-simple-php-get-code/
Share on other sites

Try this....

 

if (!isset($_GET['id'])){
   $id = "YourDefaultValue";
}
else {
   $id = $_GET['id'];
}

 

This is looking for a URL something like www.test.com?id=YourVariable

If it recieves www.test.com then it uses the default value otherwise YourVariable is passed onto $id to be used later!

 

Hope that makes some sense....

 

Basically you can use $id = $_GET['id'];

Archived

This topic is now archived and is closed to further replies.

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