Jump to content

Hide a page while redirecting to url


ken3d06

Recommended Posts

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

 

Link to comment
Share on other sites

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 by paddyfields
Link to comment
Share on other sites

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.

post-124152-0-93293400-1389880973_thumb.png

Edited by jazzman1
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.