Jump to content

help with php script please


alto

Recommended Posts

im using php script in nginx server and its working good but im not able to add more user and passwords please here is example if you can help thank you.

 

<?php

// www.server.com/auth.php?user=felix&pass=felixpassword

//check if querystrings exist or not

if(empty($_GET['user']) || empty($_GET['pass']))

{

//no querystrings or wrong syntax

echo "wrong query input";

header('HTTP/1.0 404 Not Found');

exit(1);

}

else

{

//querystring exist

$username = $_GET['user'];

$password = $_GET['pass'];

}

$savedpassword = felixpassword ;

$saveduser = felix ;

//check pass and user string

if (strcmp($password,$savedpassword)==0 && strcmp($username,$saveduser)==0 )

{

echo "Password and Username OK! ";

}

else

{

echo "password or username wrong! ";

header('HTTP/1.0 404 Not Found'); //kein stream

}

?>

 

Link to comment
Share on other sites

You need to have usernames and passwords in some sort of data store, like a database or a file. Most people use a database. If you want to have everything hard-coded then you can store username and password pairs in an array and loop through them to check.

Link to comment
Share on other sites

script by self check user and pasword in this form and take password felixpassword and for user take felix nothing else

 

$savedpassword = felixpassword ;

$saveduser = felix ;

if i put in this form evrythig will take as user and password even single leter

$savedpassword =array("felix","pass1","pass2");

$saveduser =array("felix","user1","user2");

Edited by alto
Link to comment
Share on other sites

right... but where are you checking? what's the logic you added?

 

Here is what JSG was likely suggesting

$users = array(  array("username" => "jim", "password" => "pass1"),  array("username" => "john", "password" => "pass12"),  array("username" => "julie", "password" => "pass123"));$username = $_GET["user"];$password = $_GET["pass"]; for($i = 0; $i < count($users); $i++){  $user = $users[$i];   if($user["username"] === $username && $user["password"] === $password){    echo "successfully logged in as " . $username;   }} 

Or, you could consider this. You create one array for your users, mapped to their password

$userPasswordMapper = array(  "jim" => "pass1",  "john" => "pass12",  "julie" => "pass123"); $username = $_GET["user"];$password = $_GET["pass"]; //submitted user exists in $users array//and the submitted password matches the value mapped to that user in the arrayif($userPasswordMapper[$username] && $userPasswordMapper[$username] === $password ){  echo "successfully logged in as " . $username;}
  • Like 1
Link to comment
Share on other sites

excuse me but still i dont have luck to get script working with more than one user and passwords.

 

script im using for authorization for stream.

 

my stream from server caring space for user and password and it check in auth.php user and password if exist it play if dont find user and password in auth.php it stop stream.

 

in example here

<?php

// www.server.com/auth.php?user=felix&pass=felixpassword

//check if querystrings exist or not

if(empty($_GET['user']) || empty($_GET['pass']))

{

//no querystrings or wrong syntax

echo "wrong query input";

header('HTTP/1.0 404 Not Found');

exit(1);

}

else

{

//querystring exist

$username = $_GET['user'];

$password = $_GET['pass'];

}

$savedpassword = felixpassword ;

$saveduser = felix ;

//check pass and user string

if (strcmp($password,$savedpassword)==0 && strcmp($username,$saveduser)==0 )

{

echo "Password and Username OK! ";

}

else

{

echo "password or username wrong! ";

header('HTTP/1.0 404 Not Found'); //kein stream

}

?>

its working with user felix and password felixpassword anything else will not play stream. stream look like this www.server.com/auth.php?user=felix&pass=felixpassword
now i need to add one more user or two to play stream but i dont now how for exaple www.server.com/auth.php?user=felix1&pass=felixpassword1.
i try with array but its take every name for user and password without checking for users and passwords in auth.php script.
its so confusing for me. plesase if somone have time to try help me make it working to sugest what to do to get script working with more names. perhaps to modify above script thank you very much.
Link to comment
Share on other sites

you never show how you are trying to change the code, so we can't tell you what you are doing wrong. We can't read your mind and we can't magically see the code on your monitor. All you need to do is just show us what you tried.

 

Also, a more accurate HTTP status code would be 401 Not Authorized.

Link to comment
Share on other sites

i try like this with array after i doo like in example it not cheking names it play even with single leter as user and password www.server.com/auth.php?user=d&pass=nn what i try to do is to play just with names in script

i also try more combination with array but no succes

// www.server.com/auth.php?user=felix&pass=felixpassword

//check if querystrings exist or not

if(empty($_GET['user']) || empty($_GET['pass']))

{

//no querystrings or wrong syntax

echo "wrong query input";

header('HTTP/1.0 404 Not Found');

exit(1);

}

else

{

//querystring exist

$username = $_GET['user'];

$password = $_GET['pass'];

}

$savedpassword =array("felixpass","felixpass1","felixpass2");

$saveduser = array("felix","felix1","felix2");

//check pass and user string

if (strcmp($password,$savedpassword)==0 && strcmp($username,$saveduser)==0 )

{

echo "Password and Username OK! ";

}

else

{

echo "password or username wrong! ";

header('HTTP/1.0 404 Not Found'); //kein stream

}

?>

Link to comment
Share on other sites

it doesn't seem like you've been listening to us. Please read our comments as two very simple examples have been provided to you.

Link to comment
Share on other sites

excuse me but i dont know coding comand im using coppy paste i also try some examples on my own but no succses

i try like this not working

 

<?php
// www.server.com/auth.php?user=felix&pass=felixpassword
//check if querystrings exist or not
if(empty($_GET['user']) || empty($_GET['pass']))
{
//no querystrings or wrong syntax
echo "wrong query input";
header('HTTP/1.0 404 Not Found');
exit(1);
}
else
{
$users = array(
array("username" => "jim", "password" => "pass1"),
array("username" => "john", "password" => "pass12"),
array("username" => "julie", "password" => "pass123")
);
$username = $_GET["user"];
$password = $_GET["pass"];
for($i = 0; $i < count($users); $i++){
$user = $users[$i];
if($user["username"] === $username && $user["password"] === $password){
echo "successfully logged in as " . $username;
}
}
else
{
echo "password or username wrong! ";
header('HTTP/1.0 404 Not Found'); //kein stream
}
?>
also this not working
<?php
// www.server.com/auth.php?user=felix&pass=felixpassword
//check if querystrings exist or not
if(empty($_GET['user']) || empty($_GET['pass']))
{
//no querystrings or wrong syntax
echo "wrong query input";
header('HTTP/1.0 404 Not Found');
exit(1);
}
else
{
$userPasswordMapper = array(
"jim" => "pass1",
"john" => "pass12",
"julie" => "pass123"
);
$username = $_GET["user"];
$password = $_GET["pass"];
//submitted user exists in $users array
//and the submitted password matches the value mapped to that user in the array
if($userPasswordMapper[$username] && $userPasswordMapper[$username] === $password ){
echo "successfully logged in as " . $username;
}
else
{
echo "password or username wrong! ";
header('HTTP/1.0 404 Not Found'); //kein stream
}
?>
Link to comment
Share on other sites

well, if all you are going to do is literally copy / paste, I don't think you're going to make it very far on here or in general. I know you are starting out, but take a hard look at what you have. You don't think you should change the usernames and passwords to match your particular situation?

 

If anything, this is working as expected because felix and felixpassword aren't in the map array.

  • Like 1
Link to comment
Share on other sites

I'm again. without your help i will never make script working.

I know my english isnt so good but i will explaine what for I'm using script.

 

I have nginx server using it for for streaming with rtmp module.

rtmp module suport this command

 

notify_method get;

for protecting streaming content

 

when user try to watch stream content this comand notify_method get; check it is it user authorized to watch content and its check on this location http://localhost/auth.php;

 

auth.php is script above. its working perfect with one user but i dont now how could I modify script to accsept more users and passwords

 

 

 

this script check felix user and felixpassword are they authorized to watch content. as you see in script is included felix user and felixpassword and script aloud for user felix and for password felixpassword to start playing from server my question is how to modify script to add more users and password authorized to play stream one more time i will post script please help me to modify because with my knowlege of php coding i cant do it i think for you its pease of cake and for me its mean maybe in a year.

 

thank you very much

 

<?php// www.server.com/auth.php?user=felix&pass=felixpassword//check if querystrings exist or notif(empty($_GET['user']) || empty($_GET['pass'])) { //no querystrings or wrong syntax echo "wrong query input"; header('HTTP/1.0 404 Not Found'); exit(1); }else { //querystring exist $username = $_GET['user']; $password = $_GET['pass']; }$savedpassword = felixpassword ;$saveduser = felix ;//check pass and user stringif (strcmp($password,$savedpassword)==0 && strcmp($username,$saveduser)==0 ) { echo "Password and Username OK! "; }else { echo "password or username wrong! "; header('HTTP/1.0 404 Not Found'); //kein stream }?>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...