Jump to content

POST to URL from HTML


memome

Recommended Posts

I am looking for an example script that I can learn off of. I am trying to post variables to a URL via HTML forum. I understand the HTML part, but I am a little fuzzy on the PHP end.

 

the end result of the php script would post a url like this with the variables defined in the HTML forum

 

https://mysite.com/myapplicaion?var1=var1data&var2=var2data&var3=var3data

 

 

Link to comment
Share on other sites

file.html

 

<form action="file.php" method="post">
<input type="text" name="var1" />
<input type="submit" name="submit" value="Submit" />
</form>

 

file.php

 

<?php

if(isset($_POST["submit"])) {
$var1 = $_POST["var1"];
echo "var1 = {$var1}";
}

?>

 

Very basic, just checks that the form has been submitted and outputs ;)

Link to comment
Share on other sites

<?php

if (isset($_POST['submit'])){
   
   //get variables from the URL
   $var1 = $_GET['var1'];
   $var2 = $_GET['var2'];
   //....and so on
}

?> 

<form action="site.com?var1=var1data&var2=var2data&var3=var3data" method='post'>
<input type='submit' name='submit' value='go'>
</form>

 

There is an example for you =] Just let me know if you don't understand something.

 

EDIT:

Yeah, I was beat to it. I'm going to post this anyways since I spent the time typing it :)

Link to comment
Share on other sites

Sill a little confused

 

//get variables from the URL

  $var1 = $_GET['var1'];

  $var2 = $_GET['var2'];

  //....and so on

 

This will still work if I am collecting the variables to be used in the URL. Im am trying to just make a little html/php interface to submit txt messages to my SMS provider. They stated that I need to send a message by sending a url like this:

 

 

My provider said the I would be able to use PHP to submit a URL like the one above. Most of the examples I was able to find on the net reference pull variables FROM the URL as apposed to submitting to the URL

 

I apologize for my confusion....Im such a n00b

Link to comment
Share on other sites

I Posted this somewhere else as well but I think you need the scripta as well so here!

 

<?php
//put this at the VERY FIRST LINE in your script! Line 1!!! LINE 1
$page = $_GET['page'];
//put this in a table
if ($page == NULL){
include 'pages/home.php';
}
elseif (file_exists('pages/' . $page . '.php')) {
include 'pages/' . $page . '.php';
}
elseif ($page == logout){
session_destroy();
}
elseif ($page == notloggedin){
echo 'You Are Not logged in! Too Bad';
}
else include 'pages/error.php';
?>

 

Now make a folder called pages in your document root and simplycreate php pages in it (you must include an error and home .php) Now when you link to a document lets say if your document name is test1.php you would make a like as follows:

index.php?page=test1

And from there you can assign multiple variables the sasme way but with diffrent names so you could have a page looking like

index.php?page=test1&footer=foot2&language=en&advertisement=phpfreaks

get it?

Then to display the page name on your website... Mainly only for forums! just type

<?php
echo $page;
?>

 

That was long I am going to get some coffee after that!

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.