ken3d06 Posted January 16, 2014 Share Posted January 16, 2014 Hello, When a user clicks a submit button on 'page 1' it takes them to 'page 2' that has summaries of his orders, and at the same time it gives a splashing notice of being redirected to a url (I will call it 'page 3' I want when the submit button is clicked, page 2 should be completely bypassed so that it doesnt show to the user..(I still want page 2 code to run in the background though) How do I do this Quote Link to comment https://forums.phpfreaks.com/topic/285407-hide-a-page-while-redirecting-to-url/ Share on other sites More sharing options...
paddy_fields Posted January 16, 2014 Share Posted January 16, 2014 (edited) You could just put your code for page2 at the top of page3, and make the form send to page3 originally. In answer to your question, If page2 just contains PHP code and doesn't print anything to the page, put this at the bottom of page2... header('location:page3.php'); That will then redirect the user to page3.php once the page2 code has been parsed. Edited January 16, 2014 by paddyfields Quote Link to comment https://forums.phpfreaks.com/topic/285407-hide-a-page-while-redirecting-to-url/#findComment-1465401 Share on other sites More sharing options...
jazzman1 Posted January 16, 2014 Share Posted January 16, 2014 (edited) 3 different ways come in my mind: 1. Using cURL 2.Using stdin passing variables into a terminal 3. Using iframe with hidden content The easiest way is curl. Example: form.php <?php session_start(); if(isset($_GET['submit'])){ // create a new cURL resource $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://192.168.122.159/pdo/index.php?action=".$_GET['name']); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/24.0"); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); // grab URL and pass it to the output variable $output = curl_exec($ch); // close cURL resource, and free up system resources curl_close($ch); $_SESSION['output'] = $output; // save output in session // redirect the output from our variable to the browser header('Location: display.php'); exit; } ?> <form action="form.php" method="get"> Name: <input type="text" name="name" /> <input type="submit" name="submit" value="Send!!" /> </form> index.php (second page, it shouldn't be visible) <?php $name = $_GET['action']; // $inQuery = implode(',', array_fill(0, count($names), '?')); $sql = "SELECT * FROM sakila.actor WHERE first_name IN(:name)"; $username = 'lxc'; $password = 'password'; $dbh = new PDO('mysql:dbname=sakila;host=::1;charset=utf8', $username, $password); $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // insert some data using a prepared statement $stmt = $dbh->prepare($sql); // bind php variables to the named placeholders in the query // they are both strings that will not be more than 64 chars long $stmt->bindParam(':name', $name, PDO::PARAM_STR, 64); $stmt->execute(); $row = $stmt->fetchAll(PDO::FETCH_ASSOC); echo "<pre>".print_r($row, true)."</pre>"; $stmt = null; display.php <?php session_start(); echo "<h2>Output of display page</h2>"; echo "<p>Hello freaks</p>"; echo "<h2>Output of index page</h2>".$_SESSION['output']; Result: PS: If your site requires cookies, you should include CURLOPT_COOKIEFILE and CURLOPT_COOKIEJAR to cURL script. Edited January 16, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/285407-hide-a-page-while-redirecting-to-url/#findComment-1465410 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.