If I submit the form I want register.php to fetch the proxy and name which I'm submitting from client.php

if I don't use action='register.php' then it's printing the proxy I have submitted but not printing the name.

But if I use action='register.php' to post my form to register.php then it's printing my localhost IP: 127.0.0.1 instead of the proxy I have submitted.

I don't know why curl request isn't submitting my proxy when I use register.php in action='' tag.

    if(!isset($_GET['name'])){

    echo "<form class='' method='get' action='register.php'>

        <input id='cat' type='text' name='name' maximum='10' placeholder='Enter Name' autocomplete='off' required></input>
       <input id='cat' type='text' name='proxy' placeholder='Enter Your Proxy ' autocomplete='off'></input>
        <input class='button' type='submit' value='Submit'></input>
        </form>";

        }

    if(isset($_GET['name'])){

            $number = $_GET['name'];
            $proxy = $_GET['proxy'];


        $headers['CLIENT-IP'] = $proxy;

        $headers['X-FORWARDED-FOR'] = $proxy;

        $headerArr = array();

        Foreach( $headers as $n => $v ) {

        $headerArr[] = $n .':' . $v;

        }


    Ob_start();

    $ch = curl_init();

    Curl_setopt ($ch, CURLOPT_URL, "http://localhost/register.php");

    Curl_setopt ($ch, CURLOPT_HTTPHEADER , $headerArr ); //Structure IP

    Curl_setopt( $ch, CURLOPT_HEADER, 0);

    #Curl_setopt( $ch, CURLOPT_POST, 1);

    #Curl_setopt( $ch, CURLOPT_POSTFIELDS, $data);

    Curl_setopt( $ch, CURLOPT_VERBOSE, true);

    Curl_exec($ch);

    Curl_close ($ch);

    $out = ob_get_contents();

    Ob_clean();

    Echo $out;
    }

this is my register.php

the name and proxy I'm submitting from client.php should be print here.

    Function GetIP(){

    if(!empty($_SERVER["HTTP_CLIENT_IP"]))

    $cip = $_SERVER["HTTP_CLIENT_IP"];

    else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))

    $cip = $_SERVER["HTTP_X_FORWARDED_FOR"];

    else if(!empty($_SERVER["REMOTE_ADDR"]))

    $cip = $_SERVER["REMOTE_ADDR"];

    else

    $cip = "Unable to get!";

    return $cip;

    }

    echo"IP: ". GetIP (). "
    "; 


    $name = $_GET['name'];

    echo $name;

Result is

    Ip: 127.0.0.1 \\ here I want to print the proxy I have submitted
    Rohan

As I read https://www.php.net/manual/en/reserved.variables.server.php I see issues with your register.php

Line 3 - Gets the IP.
Line 7 - Appears to get the IP.
Line 9 and 13 appear to do the same (get the IP address.)

Read the manual and look at items that return a name such as 'SERVER_NAME'.

commented: Sir I don't wanna print the 'Server Name'. I want to print the name along with IP which is being sent from 'client.php' in 'register.php' page. +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.