variable problem
Moderator: General Moderators
-
suhailkaleem
- Forum Newbie
- Posts: 12
- Joined: Thu Nov 07, 2002 9:11 am
- Contact:
variable problem
<?
$n1 = $_GET['n1'];
if ($n1 == "0" ){
$n1= "" ;
}
//This does not work
$filename = "un".$n1.".txt";
$fd = fopen ($filename, "rb");
$username = fread ($fd, filesize ($filename));
echo $username;
fclose ($fd);
//unlink ($filename);
//This works
$username="suhailkaleem" ;
//This does not work
$filename = "pass".$n1.".txt";
$fd = fopen ($filename, "rb");
$password = fread ($fd, filesize ($filename));
echo $password;
fclose ($fd);
//unlink ($filename);
//This works
$password ="excel" ;
//This does not work
$filename = "servername".$n1.".txt";
$fd = fopen ($filename, "rb");
$server = fread ($fd, filesize ($filename));
echo $server;
fclose ($fd);
//unlink ($filename);
//This works
$server ="127.0.0.1";
$port = "110/pop3";
$mailserver = "{" . "$server:$port" . "}INBOX";
$link = imap_open($mailserver, $username, $password);
$total = imap_num_msg($link);
echo $total ;
imap_close($link);
//The baove code does not work why ? but when i put constant value in varibales user name
//password and server it works but dynamuic values dont work , correct values are cooming from file but i always get an error
// Couldn't open stream {127.0.0.1 :110/pop3}INBOX in D:\p\test.php on line 48
//can any one tell me how can i use dynamic vlaues instead of condtant values
//anyhelp
//suhailkaleem
?>
$n1 = $_GET['n1'];
if ($n1 == "0" ){
$n1= "" ;
}
//This does not work
$filename = "un".$n1.".txt";
$fd = fopen ($filename, "rb");
$username = fread ($fd, filesize ($filename));
echo $username;
fclose ($fd);
//unlink ($filename);
//This works
$username="suhailkaleem" ;
//This does not work
$filename = "pass".$n1.".txt";
$fd = fopen ($filename, "rb");
$password = fread ($fd, filesize ($filename));
echo $password;
fclose ($fd);
//unlink ($filename);
//This works
$password ="excel" ;
//This does not work
$filename = "servername".$n1.".txt";
$fd = fopen ($filename, "rb");
$server = fread ($fd, filesize ($filename));
echo $server;
fclose ($fd);
//unlink ($filename);
//This works
$server ="127.0.0.1";
$port = "110/pop3";
$mailserver = "{" . "$server:$port" . "}INBOX";
$link = imap_open($mailserver, $username, $password);
$total = imap_num_msg($link);
echo $total ;
imap_close($link);
//The baove code does not work why ? but when i put constant value in varibales user name
//password and server it works but dynamuic values dont work , correct values are cooming from file but i always get an error
// Couldn't open stream {127.0.0.1 :110/pop3}INBOX in D:\p\test.php on line 48
//can any one tell me how can i use dynamic vlaues instead of condtant values
//anyhelp
//suhailkaleem
?>
-
suhailkaleem
- Forum Newbie
- Posts: 12
- Joined: Thu Nov 07, 2002 9:11 am
- Contact:
you can print all parameters passed via GET/POST with
Code: Select all
<?php
echo '<pre>GET:'; print_r($_GET);
echo "\nPOST:"; print_r($_POST);
echo '</pre>';
?>-
suhailkaleem
- Forum Newbie
- Posts: 12
- Joined: Thu Nov 07, 2002 9:11 am
- Contact:
-
suhailkaleem
- Forum Newbie
- Posts: 12
- Joined: Thu Nov 07, 2002 9:11 am
- Contact:
When you say, "This doesn't work" what do you mean?
Firstly, if you copied and pasted your error:
Secondly, what does not work with the following code? Are you not getting the file to open, or provide you with a value, or something else?
Firstly, if you copied and pasted your error:
Notice the "space" between your server and port.{127.0.0.1 :110/pop3}INBOX
Secondly, what does not work with the following code? Are you not getting the file to open, or provide you with a value, or something else?
Have you tried using a fake-dynamic filename:$filename = "un".$n1.".txt";
$fd = fopen ($filename, "rb");
$username = fread ($fd, filesize ($filename));
echo $username;
fclose ($fd);
Code: Select all
<?php
$filename = "un3.txt"; // Check to make sure this file exists
$fd = fopen ($filename, "rb");
$username = fread ($fd, filesize ($filename)); // does the file only contain one word on one line?
echo $username; // is anything be echoed here?
fclose ($fd);
?>-
suhailkaleem
- Forum Newbie
- Posts: 12
- Joined: Thu Nov 07, 2002 9:11 am
- Contact:
Code: Select all
/*
hi !
yes you were right there is space between server name but still i am unable to remove it
$username ,$password,$server are comming from file and they have correct values
*/
$username1 = $username;
$password1 = $password;
$server1 = $server;
echo $server."test<BR>" ;
echo $password."test<BR>" ;
echo $username."test<BR>" ;
/*
This echo
127.0.0.1 test
excel test
suhailkaleem test
it echo with a space between variable value and the string test .there is space in text file at the end of these values ?
*/
$username = "suhailkaleem";
$password = "excel";
$server = "127.0.0.1";
echo $server."test" ;
// This echo 127.0.0.1test no space
/*
why is that i see space between server and string when the values come from the text file , although there is no space in text file at the end of server name but when i use in my script the space appears?????
*/the variables are read from a file. register_globals has no effect on that 
fgets (which you might have used) also returns the line delimiter.
So if you have a file likewill make $server == "server1\n"; and chop() (as mentioned by Wayne) will take care of it. It's an alias for rtrim (http://www.php.net/manual/en/function.rtrim.php)
fgets (which you might have used) also returns the line delimiter.
So if you have a file like
Code: Select all
uid1,pass1,server1
uid2,pass2,server2
...Code: Select all
$content = file($filename);
foreach($content as $entry)
list($username, $password, $server) = explode(',', $entry);This function returns a string with whitespace stripped from the end of str. Without the second parameter, rtrim() will strip these characters:
...
"\n" (ASCII 10 (0x0A)), a new line (line feed).
"\r" (ASCII 13 (0x0D)), a carriage return.
...
What about this,
Cheers!
-Abdul
Code: Select all
$username1 = trim($username);
$password1 = trim($password);
$server1 = trim($server);
echo $server."test<BR>" ;
echo $password."test<BR>" ;
echo $username."test<BR>" ;-Abdul