help with php, can u use a variable as a string?
hey, im trying to make a php page that opens a few differant urls untill i finfd the right 1, it is for a challange, but ill change the code to remove any 'spoilers'
heres what i got atm…
<?php
echo "Hello World";
$part1 = "http://www.someadress";
$part2 = "00.sql";
$part3 = "_";
$days = "01";
$hours = "1000";
$url = $part1, $days, $part3, $hours, $part2;
break;
echo $url;
break;
//it just echos numbers
while($days<=30)
{
while($hours<=2400)
{
$url = $part1+$days+"_"+$hours+$part2;
$fp = @fopen($url, "r");
if ($fp)
{
echo($url);
break;
echo($fp);
break;
}
$hours = $hours + 100;
}
$days++;
$hours=1000;
}
?>```
whats wrong?
K3174N 420 wrote:
markupcode
whats wrong?
- Don't use break unless you're breaking out of a switch case or something… no need to use it in normal coding.
- Use periods to concatenate strings, not commas. ($url = $part1, $days, $part3, $hours, $part2;)
- You can't fopen a URL… you'll have to use cURL to access URLs.
Other than those… your code looks fine.
echo "Hello World";
$part1 = "***********************";
$part2 = "*****************";
$part3 = "*********";
$days = "**";
$part4 = "*";
$hours = "****";
$part5 = ".****";
$url = $part1 . $part2 . $part3 . $days . $part4 . $hours . $part5;
echo $url . "<br />";
while($days<=30)
{
while($hours<=2400)
{
$url = $part1 . $part2 . $part3 . $days . $part4 . $hours . $part5;
***$fp = fopen($url, "r");
if ($fp)
{
echo($url . "this one" . "<br />");
echo($fp);
}***
$hours = $hours + 100;
}
$days++;
$hours=1000;
}
?>```
downloaded from
http://curl.haxx.se/dlwiz/?type=bin&os=Win32&flav=-&ver=2000%2FXP
but havin a lil problem installing…
If you're using a web host, you don't need to install the extension. If you're running a web server locally (using Apache, lighttpd, or any of the other web server packages), then you'll need to install / enable the cURL extension in your php.ini. Most webhosts have this done by default, so no worries if you have one.
First, ensure that you're actually doing something with the returned data from the cURL script… cURL doesn't generate any output by default. For instance, grab the cURL response and echo it or save it to a file or something.
If you're doing that, check your web host's documentation or FAQs to ensure that the cURL extension is enabled; they should have this documented somewhere.
ok, i seem to have curl acctive….
<?php
$ch = curl_init();
echo $ch;
curl_close ($ch);
?>```
displays >> Resource id #2
I HAVE LIFE!
thanks guys, more of an update than anything, but so far my code is
<?php
$curl_handle=curl_init();
echo "Hello World";
$part1 = "http://www.hellboundhackers.org/";
$part2 = "challenges/real2/";
$part3 = "backup_2004-09-";
$days = "01";
$part4 = "_";
$hours = "1000";
$part5 = ".sql";
$url = $part1 . $part2 . $part3 . $days . $part4 . $hours . $part5;
echo $url . "<br />";
while($days<=30)
{
while($hours<=2400)
{
$url = $part1 . $part2 . $part3 . $days . $part4 . $hours . $part5;
curl_setopt($curl_handle, $url);
curl_exec($curl_handle);
echo $curl_handle . "<br />";
echo $url . "<br />";
$hours = $hours + 100;
}
$days++;
$hours=1000;
}
curl_close($curl_handle);
?>```
and this displays
```markuptest Hello Worldhttp://www.hellboundhackers.org/challenges/real2/backup_2004-09-01_1000.sql
Resource id #2
so, getting there, i just need to undurstand wth these curl commands do….
<?php $curl_handle=curl_init(); // (…) curl_setopt($curl_handle, $url); curl_exec($curl_handle); // (…) curl_close($curl_handle);
?>``` How about something like this: (only a small part of the code)
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
$result = curl_exec($ch);
echo $result;
curl_close($ch);
?>```
Assuming you are using this code to solve a HBH challenge, you probably need to send your cookies, so the server recognises you as a member who's logged in. You can do this by adding the following line:
```markupcurl_setopt($ch, CURLOPT_COOKIE,"PHPSESSID=***; fusion_user=***");```
Good luck! ;)
PS. I'd do some more research on cURL if I were you. PHP.net does cover cURL: http://nl.php.net/manual/en/book.curl.php