Jump to content

How to send $_POST into php file


f.ismayil

Recommended Posts

I have tilbud.php file that has no output. Just receives data and adds them into MySQL table. Inside tilbud.php file I have JavaScript code that calls products.php. Product.php has the following code:

 

if(!isset($_POST['userid'])) {

  echo "<script type='text/javascript'>";

    echo "window.location = 'index.php'";

  echo "</script>";

 

  exit;

}

 

So, I you call product.php without submitting $_POST['userid'] it redirects you into index.php. How to submit $_POST['userid'] into products php without using <form method='POST' action='product.php'> ?

Link to comment
https://forums.phpfreaks.com/topic/236785-how-to-send-_post-into-php-file/
Share on other sites

if(!isset($_POST['userid'])) {
  echo "<script type='text/javascript'>";
    echo "window.location = 'index.php'";
  echo "</script>";
  
  exit;
}

 

This is rather inefficient, it would be wise to have the server handle redirects.

 

if(!isset($_POST['userid'])) {
header('Location: /index.php');
}

 

As for submitting post data without using a form, you have a few options.

http://ca.php.net/manual/en/function.http-post-data.php]http://php.net/manual/en/book.curl.php[/curl]

http://ca.php.net/manual/en/function.http-post-data.php

http://ca.php.net/manual/en/function.stream-context-create.php

 

I'm sure there are others. I would go with the cURL option and possibly AJAX if you need it.

I want linux compatibility for that application. My problem now is, i can get the complete path of the application using some php function?

 

What i will do is that the application is created and saved the first time you execute the application in the index page(tr level), and saved in my singleton class of global registry thats its in S_SESSION.  So the first time its instancied, it will get the complete path.

 

The problem here i see is that the user may execute first some file in the categorias directory. Then it will get that path as a base. I will check for that as the directory structrue of the application is fixed.

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.