Jump to content

[SOLVED] Simple Redirect


Recommended Posts

Ok, so I've made a redirect but i want it to pop up with a little window when you go to it so that you have to put in like a password or something and then click ok and if you put in the wrong thing it won't let you through...would that be to hard for someone to make for me. If not please do. It will be greatly appreciated!

Link to comment
Share on other sites

What you're looking for would be more relavent in the php freelancing area.

 

If you're looking to do it yourself, what do you have so far?  Everyone here is happy to help people who are learning, but many of us are full time developers who make our living doing this.

 

Link to comment
Share on other sites

alright. well i mean i can't pay. I wish i could but i'm just a 16 year old without a job so not to much i can do as money right now. haha and it's just a simple php redirect right now

 

<?php



header('location: http://www.site.com');



?>

 

and it maybe be javascript. I don't know alot about either but I'll be learning soon hopefully

 

basically all i want is before it redirects you to the site i want a pop up kinda like an alert to pop up asking for a password. The person puts it in right it redirects them to the page and if put in wrong it does nothing

 

Link to comment
Share on other sites

oh i see what the problem is. sorry stupid mistake on my half. like i said i pretty much know zilch about scripting as of right now. i was setting the else as the site i want it to go too. see i want it to ask for the password right before it sends you to the page. and if you put it in wrong then it just doesn't redirect you to the page.

Link to comment
Share on other sites

<?php
$username = "someuser";
$password = "somepassword";
if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) {
?>
<h1>Login</h1>
<table>
<tr>
<td>Username:
<td><input type="text" name="txtUsername">
<tr>
<td>Password:
<td><input type="text" name="txtPassword">
<tr>
<td colspan=2 align=right><input type="submit"><input type="reset">

<form name="form" method="post" action="<?=$_SERVER['PHP_SELF']; ?>">


</form>

<?php
}
else {
header('location: http://www.site.com');
}
?>

 

 

Link to comment
Share on other sites

I found this which would be perfect if it redirected you when you put in the right info

 

<?php



###############################################################

# Page Password Protect 2.13

###############################################################

# Visit http://www.zubrag.com/scripts/ for updates

############################################################### 

#

# Usage:

# Set usernames / passwords below between SETTINGS START and SETTINGS END.

# Open it in browser with "help" parameter to get the code

# to add to all files being protected. 

#    Example: password_protect.php?help

# Include protection string which it gave you into every file that needs to be protected

#

# Add following HTML code to your page where you want to have logout link

# <a href="http://www.example.com/path/to/protected/page.php?logout=1">Logout</a>

#

###############################################################



/*

-------------------------------------------------------------------

SAMPLE if you only want to request login and password on login form.

Each row represents different user.



$LOGIN_INFORMATION = array(

  'zubrag' => 'root',

  'test' => 'testpass',

  'admin' => 'passwd'

);



--------------------------------------------------------------------

SAMPLE if you only want to request only password on login form.

Note: only passwords are listed



$LOGIN_INFORMATION = array(

  'root',

  'testpass',

  'passwd'

);



--------------------------------------------------------------------

*/



##################################################################

#  SETTINGS START

##################################################################



// Add login/password pairs below, like described above

// NOTE: all rows except last must have comma "," at the end of line

$LOGIN_INFORMATION = array(

  'admin' => 'password',

);



// request login? true - show login and password boxes, false - password box only

define('USE_USERNAME', true);



// User will be redirected to this page after logout

define('LOGOUT_URL', 'http://www.example.com/');



// time out after NN minutes of inactivity. Set to 0 to not timeout

define('TIMEOUT_MINUTES', 0);



// This parameter is only useful when TIMEOUT_MINUTES is not zero

// true - timeout time from last activity, false - timeout time from login

define('TIMEOUT_CHECK_ACTIVITY', true);



##################################################################

#  SETTINGS END

##################################################################





///////////////////////////////////////////////////////

// do not change code below

///////////////////////////////////////////////////////



// show usage example

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

  die('Include following code into every page you would like to protect, at the very beginning (first line):<br><?php include("' . str_replace('\\','\\\\',__FILE__) . '"); ?>');

}



// timeout in seconds

$timeout = (TIMEOUT_MINUTES == 0 ? 0 : time() + TIMEOUT_MINUTES * 60);



// logout?

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

  setcookie("verify", '', $timeout, '/'); // clear password;

  header('Location: ' . LOGOUT_URL);

  exit();

}



if(!function_exists('showLoginPasswordProtect')) {



// show login form

function showLoginPasswordProtect($error_msg) {

?>

<html>

<head>

  <title>Please enter password to access this page</title>

  <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE">

  <META HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">

</head>

<body>

  <style>

    input { border: 1px solid black; }

  </style>

  <div style="width:500px; margin-left:auto; margin-right:auto; text-align:center">

  <form method="post">

    <h3>Please enter password to access this page</h3>

    <font color="red"><?php echo $error_msg; ?></font><br />

<?php if (USE_USERNAME) echo 'Login:<br /><input type="input" name="access_login" /><br />Password:<br />'; ?>

    <input type="password" name="access_password" /><p></p><input type="submit" name="Submit" value="Submit" />

  </form>

  </div>

</body>

</html>



<?php

  // stop at this point

  die();

}

}



// user provided password

if (isset($_POST['access_password'])) {



  $login = isset($_POST['access_login']) ? $_POST['access_login'] : '';

  $pass = $_POST['access_password'];

  if (!USE_USERNAME && !in_array($pass, $LOGIN_INFORMATION)

  || (USE_USERNAME && ( !array_key_exists($login, $LOGIN_INFORMATION) || $LOGIN_INFORMATION[$login] != $pass ) ) 

  ) {

    showLoginPasswordProtect("Incorrect password.");

  }

  else {

    // set cookie if password was validated

    setcookie("verify", md5($login.'%'.$pass), $timeout, '/');

    

    // Some programs (like Form1 Bilder) check $_POST array to see if parameters passed

    // So need to clear password protector variables

    unset($_POST['access_login']);

    unset($_POST['access_password']);

    unset($_POST['Submit']);

  }



}



else {



  // check if password cookie is set

  if (!isset($_COOKIE['verify'])) {

    showLoginPasswordProtect("");

  }



  // check if cookie is good

  $found = false;

  foreach($LOGIN_INFORMATION as $key=>$val) {

    $lp = (USE_USERNAME ? $key : '') .'%'.$val;

    if ($_COOKIE['verify'] == md5($lp)) {

      $found = true;

      // prolong timeout

      if (TIMEOUT_CHECK_ACTIVITY) {

        setcookie("verify", md5($lp), $timeout, '/');

      }

      break;

    }

  }

  if (!$found) {

    showLoginPasswordProtect("");

  }



}



?>
<?php



header('location: http://blocks.dontexist.org/image_uploader');



?>

Link to comment
Share on other sites

<?php
$username = "someuser";
$password = "somepassword";
if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) {
?>
<h1>Login</h1>
<table>
<tr>
<td>Username:
<td><input type="text" name="txtUsername">
<tr>
<td>Password:
<td><input type="text" name="txtPassword">
<tr>
<td colspan=2 align=right><input type="submit"><input type="reset">

<form name="form" method="post" action="<?=$_SERVER['PHP_SELF']; ?>">


</form>

<?php
}
else {
header('location: http://www.site.com');
}
?>

 

 

 

looks perfect!

accept when i hit submit query nothing happens? =[

am i doing something wrong?

I changed it to this just as a test to see if it worked..

 

<?php
$username = "admin";
$password = "password";
if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) {
?>
<h1>Login</h1>
<table>
<tr>
<td>Username:
<td><input type="text" name="txtUsername">
<tr>
<td>Password:
<td><input type="text" name="txtPassword">
<tr>
<td colspan=2 align=right><input type="submit"><input type="reset">

<form name="form" method="post" action="<?=$_SERVER['PHP_SELF']; ?>">


</form>

<?php
}
else {
header('location: http://www.google.com');
}
?>

Link to comment
Share on other sites

<?php
$username = "admin";
$password = "password";
if ($_POST['txtUsername'] != $username || $_POST['txtPassword'] != $password) {
?>

<form name="form" method="post" action="<?=$_SERVER['PHP_SELF']; ?>">


<h1>Login</h1>
<table>
<tr>
<td>Username:
<td><input type="text" name="txtUsername">
<tr>
<td>Password:
<td><input type="text" name="txtPassword">
<tr>
<td colspan=2 align=right><input type="submit"><input type="reset">




</form>

<?php
}
else {
header('location: http://www.google.com');
}
?>

Link to comment
Share on other sites

What dezkit posted should work =D

 

Tizag has some great tutorials on PHP - I think if you hit a few of those up, you'd have a grasp on the basics of the language in no time.  You seem like a smart kid!

 

Also, if you're a proficient programmer - you get ALL the girls.  I can't tell you how many times a day smokin' hot girls approach me trying to claw my clothes off while screaming "Nafetski!  Your code is so elegant!  Have my babies!".

 

*gets off his his flying unicorn*

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.