Jump to content

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'];

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.