View Single Post
Old 03-13-2009, 04:11 AM   #2 (permalink)
tony
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

I don't think there is only a way doing it with POST data, but it's by using a socket to the domain. however, the sockets won't send the user to the page, it would only send a POST request with its fields.

I don't think it is possible without using javascript.

this code can do the job, but is a vile hack:

PHP Code:
<?php

if($_POST['ur_submit']){
    
$url $_SERVER['HTTP_HOST'].'/'.$_POST['userRequest'];
    
header("Location: ".$urlTRUE307);
    
    
//or instead you can try this
    /**
    $post_data = 'var1=123&var2=456';
    $content_length = strlen($post_data);
    $host = 'your.host.com';
    
    header('POST '.$_POST['userRequest'].' HTTP/1.1');
    header('Host: '.$host);
    header('Connection: close');
    header('Content-type: application/x-www-form-urlencoded');
    header('Content-length: ' . $content_length);
    header('');
    header($post_data);
    
    exit();
    */
}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <select name="userRequest" id="userRequest">
        <option value="page1.html">Option1</option>
        <option value="page2.html">Option2</option>
    </select>
    
    <input type="submit" name="ur_submit" id="ur_submit" value"Submit" />
</form>
In the code there are 2 ways to do it, the first one is the code
PHP Code:
header("Location: ".$urlTRUE307); 
This is basically a hack because it messes up with the search engines and they won't index the file that has this code because it would have this redirect header. Also the web browser would ask the user if he truly wants to redirect, except for one (IE) that doesn't implement the right standards.

The second way (that is commented out) is just an imaginary code from that some people says it works, I am not sure, I haven't test it.

Another way to do it is using javascript kinda like this:

Code:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title><!-- Insert your title here --></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<style type="text/css">
form#redirect{
    display: none;
}
</style>

<script type="text/javascript">
window.onload=function(){
    var form=getElementById("redirect");
    form.submit();
}
</script>

</head>
<body>
<?php
if($_POST['ur_submit']){
    $redirect = $_POST['userRequest'];
?>

<form name="redirect" id="redirect" action="<?php echo redirect; ?>">
    <input type="hidden" name="var1" value="123" />
    <input type="hidden" name="var2" value="456" />
</form>

<?php
}
?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <select name="userRequest" id="userRequest">
        <option value="page1.html">Option1</option>
        <option value="page2.html">Option2</option>
    </select>
    
    <input type="submit" name="ur_submit" id="ur_submit" value"Submit" />
</form>


</body>
</html>
I am not good at JavaScript either.
The problem with not being able to send post requests without submitting forms in php is because it runs on the server and the post requests are send on the client side, so we need JavaScript to send a post too, as far as I know.

I hope this helps.

Last edited by tony : 03-13-2009 at 09:10 PM.
tony is offline  
Reply With Quote
The Following User Says Thank You to tony For This Useful Post:
allworknoplay (03-13-2009)