Jump to content

Recommended Posts

Hi, I know i'm probably in the wrong forum but I didn't see a "php help".

 

I've seen websites have for eg.

 

my-ultracooldomain.com/index.php?page=coolio

 

I'm not completely sure how they do that, but I know it has PHP involved, and its all in one file.

 

If somebody could give me a example code, it would be fantastic -

I'm only new to the forum, and PHP.

Link to comment
https://forums.phpfreaks.com/topic/142400-php-variables/
Share on other sites

I would reccommend reading some "Basic PHP Tutorials" (google it), they should get you started.

 

For your specific question though;

 

Every server has the script, the php file that gets called from the URL (Browser); eg:

 

 

 

You can pass arguments to these files by adding an "Argument String", eg;

?argument=value

 

 

 

You can pass multiple arguments by concatenating each one with a & (ampersand), eg;

?argument1=value1&argument2=value2&argument...

 

You can also pass arguments to the file via a form - via HTML input elements, the "name" field of the input element will the the "Argument Name", and the value will be whatver the value is on the form. This is how forms work.

 


 

So, if your script were to receive a request like this:

http://www.somenet.com/index.php?therequestname=therequestvalue

 

You can access the "Arguments" that have been passed to the script/server via php's built in globals.

 

 

 

For Arguments passed via the URL use the $_GET array, eg;

<?php

echo($_GET['therequestname']);

// Outputs:
// therequestvalue

?>

 

For Form Data you would use the $_POST array:

<?php

echo($_POST['therequestname']);

// Outputs:
// therequestvalue

?>

...

 

By default, most browsers (if not all) submit a form via the URL - this is bad practice since if your submitting large amounts of information (name/address/email/description/location/etc etc), your url length will most likely break the URL Length Limit.

 

So make sure in your <form> tag you set method="post" ie:

<form method="post">

 

 

Hope this clears things up for you;

Link to comment
https://forums.phpfreaks.com/topic/142400-php-variables/#findComment-746131
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.