php模拟post模式打开页面
php模拟post方式打开页面
我登录了后台,想在后台模拟用post方式跳转到另一个页面并处理这些数据,可是总是弹出叫我重新登录的提示,我估计是模拟post方式跳转时,已经失去了$_SESSION值。请问该怎么处理这种情况?
代码如下:
$post_string='detail=addaction&subva=0&name=testadmin&password=123456&sex=1'
$context = array(
'http' => array(
'method' => 'POST',
'header' => 'Content-type: application/x-www-form-urlencoded\r\nUser-Agent : Jimmy\'s POST Example beta\r\nContent-length:'.strlen($post_string)+8,
'content' => 'mypost='.$post_string
)
);
$stream_context = stream_context_create($context);
$data = file_get_contents("http://xxxxxxxx/xxxx/main.php", false, $stream_context);
echo $data;
------解决方案--------------------
1)先POST数据到到登陆画面
2)返回的结果里会有一个Cookie:SessionID=xxxxxxxxxxxx
3) 取出SessionID,然后按照你上面的方式POST
'header' => 'Content-type: application/x-www-form-urlencoded\r\nUser-Agent : Jimmy\'s POST Example beta\r\nContent-length:'.strlen($post_string)+8,
'header' => 'Cookie: SessionID=xxxxxxxxx;Content-type: application/x-www-form-urlencoded\r\nUser-Agent : Jimmy\'s POST Example beta\r\nContent-length:'.strlen($post_string)+8,
Cookie的格式记不大清楚,以上只是Sample.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Convert basic data types to strings using Java's String.valueOf() function In Java development, when we need to convert basic data types to strings, a common method is to use the valueOf() function of the String class. This function can accept parameters of basic data types and return the corresponding string representation. In this article, we will explore how to use the String.valueOf() function for basic data type conversions and provide some code examples to

Replace characters (strings) in a string using Java's String.replace() function In Java, strings are immutable objects, which means that once a string object is created, its value cannot be modified. However, you may encounter situations where you need to replace certain characters or strings in a string. At this time, we can use the replace() method in Java's String class to implement string replacement. The replace() method of String class has two types:

Context is the environment and status information when the program is executed. It can include a variety of information, such as the value of variables, the call stack of functions, the execution location of the program, etc., allowing the program to make corresponding decisions based on different contexts. and perform corresponding operations.

Hello everyone, today I will share with you the basic knowledge of Java: String. Needless to say the importance of the String class, it can be said to be the most used class in our back-end development, so it is necessary to talk about it.

How to use context to implement request caching in Go Introduction: When building web applications, we often need to cache requests to improve performance. In the Go language, we can use the context package to implement the request caching function. This article will introduce how to use the context package to implement request caching, and provide code examples to help readers better understand. What is context? : In the Go language, the context package provides a way to pass between multiple goroutines

How to use context to implement request link tracking in Go. In the microservice architecture, request link tracking is a very important technology that is used to track the delivery and processing of a request between multiple microservices. In the Go language, we can use the context package to implement request link tracking. This article will introduce how to use context for request link tracking and give code examples. First, we need to understand the basic concepts and usage of the context package. The context package provides a mechanism

How to use context to implement request timeout control in Go Introduction: When we make network requests, we often encounter request timeout problems. A network request that does not respond for a long time will not only waste server resources, but also affect overall performance. In order to solve this problem, the Go language introduced the context package, which can be used to implement request timeout control. This article will introduce how to use the context package to implement request timeout control in Go, and attach corresponding code examples. 1. Understand the context package co

PHP is a programming language widely used in website development, and page jumps and carrying POST data are common requirements in website development. This article will introduce how to implement PHP page jump and carry POST data, including specific code examples. In PHP, page jumps are generally implemented through the header function. If you need to carry POST data during the jump process, you can do it through the following steps: First, create a page containing a form, where the user fills in the information and clicks the submit button. Acti in the form
