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
https://forums.phpfreaks.com/topic/60958-post-to-url-from-html/
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
https://forums.phpfreaks.com/topic/60958-post-to-url-from-html/#findComment-303288
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
https://forums.phpfreaks.com/topic/60958-post-to-url-from-html/#findComment-303291
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
https://forums.phpfreaks.com/topic/60958-post-to-url-from-html/#findComment-303340
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
https://forums.phpfreaks.com/topic/60958-post-to-url-from-html/#findComment-303353
Share on other sites

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.