Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9254289
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:25:49+00:00 2026-06-18T11:25:49+00:00

I am trying learn PHP by actually doing something I may find useful for

  • 0

I am trying learn PHP by actually doing something I may find useful for myself. There is a betting agency in my country which has a website where I can check if I won or not by entering a ticket number. I am trying to write a PHP script to check if range of tickets are worth anything so I don’t have to enter every ticket manually on their website.

I managed to do that. But now I want to save the response I get from their server in a file. I run into serious problems with this. I managed to save the verbose into a file but I am unable to make the script save to a file what I see on the screen inside my browser after running the script.

Here is the code:

<?php

function check($week, $base, $startcheck, $endcheck, $verbose = "true"){

// Set file path
$verbosePath = 'publicbet.txt';
echo "Saving the tickets to: <b>$verbosePath</b>\n";

// Initiate numbering
$i = 0;

// Initiate publicbet.ro IP
$ip = "80.86.107.93";

// Loop
while ($startcheck <= $endcheck){

    // Generate tickkey
    $tickkey = $week.$base.$startcheck;

    // get the current server time
    $time = date('d-m-Y H:i:s');

    // Open a new cURL resource
    $ch = curl_init();

    // Stuff
    curl_setopt($ch, CURLOPT_VERBOSE, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
    curl_setopt($ch, CURLOPT_STDERR,$f = fopen($verbosePath, "a"));
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:18.0) Gecko/20100101 Firefox/18.0");

    // publicbet.ro may be checking the IP adress
    // from where the $tickkey is sent in order to
    // check for abnormalities; we will send the
    // IP adress of the website:)
    $headerarray = array(
        "X-Forwarded-For: $ip");

    // Set the URL and other options
    curl_setopt($ch, CURLOPT_URL, 'http://publicbet.ro/gettickinfo2.php?lang=ro&tickkey='.$tickkey);
    curl_setopt($ch, CURLOPT_REFERER, 'http://www.publicbet.ro/');
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headerarray);

    // Executing cURL
    curl_exec($ch);

    // Close cURL resource, free up system resources
    curl_close($ch);
    fclose($f);

    // Showing informtion
    $v .= "<br />$i. At <b>$time</b> the server checked the tickkey: <b>$tickkey</b> and returned the tickket: ";
    if ($verbose == "true"){
        echo $v;
        $v = '';
    }

// Modifying values
$startcheck++;
$i++;

}

}

if ($_POST[week] && $_POST[base] && $_POST[startcheck] && $_POST[endcheck]){
check($_POST[week], $_POST[base], $_POST[startcheck], $_POST[endcheck]);
}
else {

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>

<title>publicbet.ro</title>

</head>

<body>

<h1>Check your tickets here</h1>

<form action="<?php echo $_SERVER[PHP_SELF];?>" method="post">
    <table>
        <tbody>
            <tr>
                <td>week:</td>
                <td>base:</td>
                <td>start check:</td>
                <td>end check:</td>
            </tr>
            <tr>
                <td><input type="number" name="week" min="00" max="54" maxlength="2" size="2" value=""/></td>
                <td><input type="number" name="base" maxlength="11" size="11" value=""/></td>
                <td><input type="number" name="startcheck" maxlength="6" size="6" value=""/></td>
                <td><input type="number" name="endcheck" maxlength="6" size="6" value=""/></td>
            </tr>
        </tbody>
    </table>
    <br /><input type="submit" value="Check!" />
</form>

</body>

</html>

<?php } ?>

So please tell me if there is any method of doing what I am willing to. I would be really pleased.

If you want to test the script use these values:
week: 05
base: 16010234203
start check: 350900
end check: 350920 .

It will return 19 false tickets and 1 true. I want all this text which is showing up to be exported to a text file rather than showing on my screen.

Is there a way to do this?

Thank you in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:25:50+00:00Added an answer on June 18, 2026 at 11:25 am

    Set CURLOPT_RETURNTRANSFER to true, and then where you do curl_exec(), assign it to a variable like this:

    $data = curl_exec($ch)
    

    Then you can save it like this:

    file_put_contents('my_file.txt', $data);
    

    Use constants instead of string literals for things like true and false etc.. I see in your function arguments you do $verbose = "true", this could be replaced with $verbose = true.

    You also are using constants where you should actually be using string literals, for example $_POST[base] should be $_POST['base'] or $_POST["base"]

    Please don’t use $_SERVER['PHP_SELF'] like that, it leaves you very open to XSS attacks, etc. You can do action="" and it will post to the page in question, like PHP_SELF

    Where you are doing

    if($_POST[base] .....)
    

    I recommend doing this instead:

    if(isset($_POST['base'], $_POST['somethingElse'], $_POST['anotherField'])) {
        // yay
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to learn myself PHP with some database interaction and I am trying to
I'm trying to learn HTML and PHP. In an example which i found over
Im trying to learn php by doing a little project using apache server. I
I'm trying to learn php but something goes wrong... When I use this code:
I'm trying to learn PHP, and I figured I'd make myself a simple exercise
I'm a newbie programmer doing his best to self learn PHP. I'm trying to
I am trying to learn PHP classes so I can begin coding more OOP
i'm trying to learn php/mysql. inserting data into mysql works fine but inserting those
Trying to learn about php's arrays today. I have a set of arrays like
I am developing in C++ and is trying to learn some php. I was

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.