ryantroop 177 Practically a Master Poster

ActiveX objects, as far as I know, requires some sort of Microsoft intervention or emulation... that is, you probably need to do more than just create an active X object in script.

I assume, then, that you are running this in IE and on Windows, or are familliar with this type of object (I am not).

However, a quick lookup to MSDN says:
http://msdn.microsoft.com/en-us/library/2z9ffy99

Looks like you are close. GetFile seems to require an absolute path. Try instead:

fileObj = fso.GetFile("C:\foo.txt"); //this assumes the file lives on the C:\ drive.

Hope that helps.

Alternatively, as I had suggested above (and others also tried to build upon), is you upload a file to your server using a traditional file input (<input type="file" name="upload" .... />), and let the server process the file for you, then spit out a return value that can be JSON encoded or any other encoding you like, and then store that in a javascript variable. This would be cross browser / cross platform, and allow you to do a bit more with the data coming in.

Ryan

ryantroop 177 Practically a Master Poster

The only way I can think of doing it is to submit a file (via ajax or iframe) and then the callback or whatever method you prefer sets the value of a variable.

Javascript is abstracted from the OS/File System for security reasons. The user needs to "give" you the file before you can do anything with it. However, you are setting a "cookie" or local storage variable, you may be able to do something there. However, I think it would be fairly limited due to size contraints and the fact that you need to set the file before you can edit it.

Perhaps if you explained what you were trying to do someone can give a good starting point for research or code example?

ryantroop 177 Practically a Master Poster

you can use javascript and check the inputElem.value.length > 0
you can use PHP to check isset($_POST['pw']); //validates false if empty

lastly, you can use ^$ to match an empty string...

I hope that helps...

Ryan

ryantroop 177 Practically a Master Poster

... erm... is this remote server a database? an api?

So many questions :-/

ryantroop 177 Practically a Master Poster

interesting cereal...

I get that you are doing that because they would validate, but wouldnt this require that it compares each record by hashing (and reading, anyway) it in order to compare?

How would hashing the string be faster than simply checking if the string is the same, especially when you are dealing with potentially thousands or hundreds of thousands of records?

why not just sanitize the post and then

select * from table where title = 'POST' limit 1

and then, I agree, check for mysql_num_rows() > 0;

This way, I believe, you are allowing the database to work off indexes naturally, and if you create a clustered index on ID then you can just replace * with ID and that should work too...

ryantroop 177 Practically a Master Poster

If I understand the question correctly, I believe you are trying to use PHP as an intermediary between two systems.

If that is the case, this may help:
http://forums.devshed.com/php-development-5/help-using-fopen-and-fwrite-with-a-url-53394.html

ryantroop 177 Practically a Master Poster

You are doing nothing wrong.

As long as you understand what the redirect is doing (basically clearing your GET/POST stack), you're fine :)

He suggested doing a POST (instead of a GET, which uses the URL), as it allows for more flexibility, and the ability to do a bit more behind the scenes without cluttering up a URL.

Generally, you use the URL (or, GET) when you want to allow linking. So, a specific product can be:

https://www.mycoolsite.com/products?ProdID=121

however, lets say you keep up with this, and you decide to keep using GET (or the URL) for adding stuff...

https://www.mycoolsite.com/products?ProdID=121&AddOns=1,2,3,5,6,9,10,11&ReferalSite=foo123&SomeOtherParam=areallylongurlencodedstringwith%20forspacesorpossibly+forspaceandalotofotherweirdstuff

that URL is far from pretty and annoying to remember. Sure, you can learn about URL rewrites and all the good stuff that makes a site scalable with a data driven back end, but that comes with practice and learning about how the technologies work. You could also "hide" a lot of that and make a POST through a form, and use hidden fields as necessary, etc...

In short - there is more than one way of doing things. Some are just more "right" for the job than others.

To repeat - you are doing nothing wrong.

All of us have our own idea of good development. In this particular case, I would side with diafol and actually store a user's activty in a database to keep track. It's much safer if the data is potentially going to give you money, and when you are dealing …

ryantroop 177 Practically a Master Poster

Fair. But what if other params on the stack are also being tested. You have now blown away the stack. It's not that his script is wrong, its that he didn't understand the method of gets and posts. I would discourage a redirect, as it would just lead to further confusion and frustration down the line (unless that is a desired behavior.)

ryantroop 177 Practically a Master Poster

Heh.. welcome to the world of "stored" values and URL management.

Since you are doing a GET (or a POST), the value gets stored in the URL. When you refresh the page, you are basically resending the URL with the parameters still in place.

So, your session variable (where you "store" the value) is simply doing what you are asking it to - the $_GET is set, so update the session variable by +1.

Tada!

The solution to your problem? Don't refresh. :-/

Or, you can play with URL rewrites, but then you are sort of defeating the use of "GET" as a way to keep a "trail" to a location...

There is nothing wrong with your code. Instead of refreshing, get rid of the the ?add=1 in the URL and hit enter.

Keep in mind, if you did this with a "POST" you would get a message telling you that you are "resending" data. It would not in any way solve your problem.

Hope that helps,

Ryan

ryantroop 177 Practically a Master Poster

You are very likely going to be ignored as this is a "do this for me" "question" as opposed to you trying it first and getting help when you get stuck. The purpose of the classes you are taking is to apply what you have learned...

These are pretty straight forward word problems... if you are doing these queries by hand, as a single run call, these should be very simple as they are pretty basic SQL mixed with SQL Math.

It looks like all of them will require some sort of join between a customer table and a sales rep table. Perhaps you could work on getting the data first, then do the math after...

if you are indeed doing triggers on your first week of SQL, then this page will help you as it has a nice example as the first comment, and you can base your work off of it.

http://dev.mysql.com/doc/refman/5.0/en/triggers.html

If you have specific questions I will be happy to answer them if I am able.

ryantroop 177 Practically a Master Poster

heh.. Im guessing your problem starts on line 31 and ends on line 65...

why are you doing a self-executing function before the window has loaded? I get it's top down, but you're defining and running code as it's being read. You're not getting very much speed boost by doing this.

Line 40, you are using an HTML collection, who has an index that starts at 0, but you go to <= of the collection's length (therefore, you are 1 higher than existing -> this makes an error on line 41 because tab[i] does not exist, so getting a property of tab[i] would result in failure because you cannot get a property of undefined).

Lastly, and I could be wrong about this... but meh, Ill toss it out as theory... since you are self-executing and not naming the function (it is anonymous), you are making functions that are not in the window scope implicitly (which makes them single run). So, you may be trying to execute code that doesn't really exist. Even if you were to name the function (function foo() { })(); you still may come across the problem of being out of scope. -- edit: Especially on line 62, where "this" most definately does not refer to the window or any given element on the page, but instead the anonymous function (I am 99% sure of this...). Instead, you should be passing in the event, and get the source element of the event, but doing that through an …

ryantroop 177 Practically a Master Poster

I work in a microsoft shop, and I can't sing praises for visual studio express enough. Some people don't like it, but it's super simple in my humble opinion.

As for books... html and css is pretty repetitive... so the books you got are getting you in the right direction.

Going through the w3schools tutorials are never a bad thing, and simply trying things on your own and seeing if you "can" do it because you're interested in it will go a long long way.

The wonderful part of personal code that you are learning from is that if you break it:

1) no one is likely to see it
2) you can try goofy stuff without fear of "breaking" something other than layout/colors/etc...
3) if you are truly interested in it, you will learn and grow.
4) you will beging to know what questions to ask, and by reading though forums like DaniWeb you will understand what everyone is talking about.

I read through answered questions all the time just to see solutions and see if it's something I had never thought of, or just to see if I was spot on with how I would have handled the same situation.

Books are fine for starting and getting a general idea. Doing, practicing, and owning your own code will help you develop your skills and become comfortable enough to rarely look at a book ever again (and instead, learn to google it like the rest of …

ryantroop 177 Practically a Master Poster

My take in a nut shell:

There are certain camps in programming -- those who like complete control, and those who don't mind trusting others to do some of the annoying work.

C/C++ --> Meant to be compiled. You are forced to do memory management. It runs very close to the hardware level, which means it doesn't have a whole lot of overhead when executing. In general, web sites wont use it unless it's a web service or custom server that uses C/C++ as a back end (which is what PHP was meant to do).

JAVA/C# --> Memory management done for you. After that, JAVA requires a VM to run, and has a lot of other issues that programmers tend to dislike. It's also not very secure. C# is very closely tied to Microsoft, so some people dislike it for that alone (and .NET). They are used to develop anything from stand alone apps to web tools, though it's not commonly front-facing any longer (JAVA used to be, but I haven't seen it on the web in a while, now...)

Perl --> I don't know much about it other than I don't want to learn it because that means I have to read it. It's old.

PHP --> Dynamic web scripting / software development. In its current state, it can tackle just about everything from socket programming to massive data management. While it can be compiled, it's generally not used in such a manner. It's a server side web programming …

ryantroop 177 Practically a Master Poster

Im not sure how the generic buttons work, but you could put a "disabled" class (or attribute if it's an actual submit button) on the button, and wait for your callback to determine what happened...

Im not sure that's even a possibility for you...

You could do something like...

var page = window.open(paypalurl);
disableClickFunction(); //change it's class, click handler, etc...
page.onbeforeunload = allowClickFunction; //set class/click handler/etc.. back to original state.

Again, Im not sure if you will be able to keep reference to the child window since it's cross domain... but it's worth a shot?

ryantroop 177 Practically a Master Poster

:-/

assuming you have connected to the database correctly...

$result = mysql_query("select * from table1 where id=$_POST[ID]");
while ($data = mysql_fetch_array($result))
{
    foreach($data as $k=>$v)
        echo ($k . " = " . $v);
}

or.. something to that effect... but since we are all moving to mysqli, this is already horridly outdated.

Check out http://www.php.net/manual/en/mysqli.quickstart.statements.php

To expand...

When you query with php, you are asking for a "result" object (or, to be syntactically correct, a resource). You then need to iterate through the object/array/resource/whatever in order to actually get your data.

ryantroop 177 Practically a Master Poster

if an input field is flagged disabled it will not post in a form submission.

So..

<form method="post" action="whatever.cfm">
<input name="a" type="text" />
<input name="b" type="text" disabled="disabled" />
<input name="c" type="text" disabled="disabled" />
<input type="submit" value="submit">
</form>

in javascript you can add or remove the attribute like so:

<script>

    var oFormElemb = document.forms[0].b.removeAttribute("disabled"); //enable element
    var oFormElema = document.forms[0].a.setAttribute("disabled", "disabled"); //disable element

</script>

the reason you need "disabled" to equald "disabled" is that in HTML all that is required is the word,
i.e. <input name="a" type="text" disabled /> however, in XHTML (and to make IE happy) you need it to equal something, therefore the standard is to make it equal disabled.

Hope that helps!

Ryan

ryantroop 177 Practically a Master Poster

I think that this is a fundamental misunderstanding of PHP and how it works.

When you "view source" on a web page created with PHP, you won't see any PHP code, but instead you will see the HTML that is rendered from the PHP.

The ONLY way to view PHP code is to have the file on your computer and opening it with a text/code editor of your choice. Yes, this includes notepad or whatever you like.

By the time a PHP page reaches the browser, it has already been "executed" and therefore is no longer viewable.

Does that help?

ryantroop 177 Practically a Master Poster

And Microsoft's version was JScript! :)

ryantroop 177 Practically a Master Poster

or, just don't put anything for display and it's natural state will take over. At least, I believe that to be the case...

ryantroop 177 Practically a Master Poster

Javascript is based on ECMAScript, which is then intepreted in a "sandbox" which is controlled by a browser to interpret the script. Javascript exists solely as a client side language, which means it requires a browser to function. This is, of course, ignoring server side javascript, which is (for the sake of this discussion) going to be ignored since it is a special use case, and not typical of the use of javascript on the web.

JAVA is a language that was developed by SUN Microsystems (yeah?). It runs off a "virtual machine", which is on a users machine, and interprets the code into byte-code for the machine it is instaleld on. JAVA comes with a bunch of stuff that makes development "easier" or "faster" if you know how to use them. JAVA can be run on any computer that has JAVA installed (the VM), but it is version dependent.

TL:DR; Javascript is a web language. JAVA is a stand-alone language, which can be integrated with browsers, run as a stand alone application, or run as a unifying programming tool, as long as the system running it has the VM instsalled.

That said, I dont like JAVA. C/C++/Python ftw! :)

Also, wikipedia is your friend.

ryantroop 177 Practically a Master Poster

Great! Mark it solved and happy coding :)

ryantroop 177 Practically a Master Poster

it looks like youre returning a script tag from the AJAX call. That's fine, if the script tag does something.. in this case, when URL encoded, it seems to do a lot of document.writes with data... Something Im sure you can do far more cleanly with some work, but that's another issue.

Since youre using innerHTML, the script tag is going to be ignored (if I recall correctly). I believe that you will have to actually create a script element on the page, give it a source, then append it to the document item you want it to be part of. I am fairly certain that you will not want the http:// as part of the source, as that will probably raise cross site scripting errors.

Your php script should simply return the src of the js file you want to insert.

Your code would look something like...

function loadPageContents() {
  var AJAX = new XMLHttpRequest();
  AJAX.open('GET','rss2.php',true);
  AJAX.onreadystatechange = function() {
    if(this.readyState==4 && this.responseText) {
      var Script = document.createElement("SCRIPT");
      Script.src = this.responseText; //this should be a relative path...

      var Container = document.getElementById('RSS_Feed');
      Container.appendChild(Script);

      setTimeout(loadPageContents, 5000);
    }
  }
  AJAX.send(null);
}

However, this would probably end up making a TON of code spattering all over your page...

Also, your return is sending back a <head> node, a <link> a <div> and then finally the script tag.

You're making bad markup that way...

I think you need to reconsider how you are pushing data to your page.. the PHP should be …

ryantroop 177 Practically a Master Poster

XMLHttpRequest is case sensitive.

line 6 should be:

var AJAX = new XMLHttpRequest();

also, relooking through your code,

you never close your script tag in the body... try this instead:

<head>
<link rel="stylesheet" type="text/css" href="rss.css" media="screen" />
<script language="javascript" src="js/jquery-2.0.1.min.js"></script>
<script language="javascript">
function loadPageContents() {
  var AJAX = new XMLHttpRequest();
  AJAX.open('GET','rss2.php',true);
  AJAX.onreadystatechange = function() {
    if(this.readyState==4 && this.responseText) {
      document.getElementById('RSS_Feed').innerHTML = this.responseText;
      setTimeout(loadPageContents, 5000);
    }
  }
  AJAX.send(null);
}

function body_load()
{
  setTimeout(loadPageContents, 5000);
}

}

</script>
</head>
<body style="margin: 0px;" onload="body_load();">
<div id="RSS_Feed">
</div>
</body>
ryantroop 177 Practically a Master Poster

may just be a stylistic thing... but Im not sure why you do

loadingPage = setTimeout(....);

I do not believe setTimeout returns anything... however, that's also not your problem.

While doing a setTimeout('string', number) will essentially do an implicit eval on the string, it's "bad mojo" and may be the source of your problem.

Try instead to replace that line with:

setTimeout(loadPageContents, 5000);

You don't need the () as it is implied in the setTimout() that the function is being called.

I think that should fix your problem... but shrug I have been wrong in the past ;)

ryantroop 177 Practically a Master Poster

Yes, the above is a much better approach :)

Note to self: don't answer questions late at night without thinking them through..

you are correct that making a new page each time would be a storage nightmare.

ryantroop 177 Practically a Master Poster

So the box you type in is an element of a "FORM" (the HTML part).. specifically:

<form action="http://www.daniweb.com/web-development/javascript-dhtml-ajax/threads/456118/dynamically-creating-new-page" method="post" accept-charset="utf-8" id="reply-form" class="user-input"> ......

and a ton of other stuff they use to make it look pretty.

This form posts (method="post") a bunch of data (form elements, which have been omitted for space) to the page (action="....") and the page has PHP on it that knows how to handle the data.

Now lets say the page didn't exist (like you're saying).

Depending on how you have your structure set up, you can use PHP (or any server side language) to make a new directory or file based on whatever you have set up. In the case of daniweb, they rely on a folder defauling to index.php when an index.html is not present.

In php, you would use something like:

if (!file_exists('path/to/directory')) {
    mkdir('path/to/directory');
}

(borrowed the above from http://stackoverflow.com/questions/2303372/create-a-folder-if-it-doesnt-already-exist)

mkdir makes the directory, it's then up to you to tell it to make a page (or file) as well..

it may not be the exact way daniweb does it, but they probably use something similar to file_put_contents() or a series of functions that emulate it. You can find that here:
http://www.php.net/manual/en/function.file-put-contents.php

In short, there is a forum "template" that daniweb copies to a new directory based on the thread title. The directory is created upon the initial form post (the poster), and the page has script to handle successive setting and getting …

ryantroop 177 Practically a Master Poster

Im 99% sure this site is HTML front end with JavaScript for dynamic page enhancements (all the fun animation stuffs), CSS to make it pretty, with a PHP back end most likely drawing content fron a MySQL database.

The HTML is what gives the page "structure"
CSS tells the browser (IE, Chrome, etc..) what the layout/flow of the page should look like.
The Javascript breaks it... no wait.. it "enhances" it. That's the one... It also helps modify the CSS if necessary, or make calls behind the scenes.

The PHP is what does repetitive "dynamic" creation of content. It pulls data from a database (in DaniWebs case, most likely MySQL), and displays that content in the defined structure of the HTML/Javascript/CSS.

Is that what you were looking for?

ryantroop 177 Practically a Master Poster

so, without you knowing how PHP is used, it's a bit difficult.. but maybe this will help...

2 pages.

Page 1:
example.html

<html>
<head>
<title>AJAX Example</title>
<script type="text/javascript">

function myAJAX()
{
  var textBox = document.getElementById("myText");
  var myString = textBox.value;

  if (myString.length.replace(" ","") < 1)
    {
      alert ("You need to put something in the box!!!");
      return false;
    }

  //try to create an AJAX object in the browser....
  var AJAXObj;

  try
    {
      AJAXObj = (window.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP"));
    }
  catch (e)
    {
      alert ("Your browser does not support AJAX calls. Sorry :-/");
    }


  //set a callback function, for when we get a response from the server (the PHP page).
  AJAXObj.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
        alert(AJAXObj.responseText);
    }
  }


  //try to open a connection: open(METHOD, URL, ASYNC) -- since we are doing a "GET" we are going to add
  //all of our params to the "URL" by adding a "?" and then name=value pairs.

  AJAXObj.open("GET", "myAJAX.php?string=" + myString, true);
  AJAXObj.send(); //sends our request.
}

</script>
</head>
<body>
<input type="text" id="myText" />
<input type="button" onclick="myAJAX();" />
</body>
</html>

save the above as example.html
next page is going to be our PHP page:
myAJAX.php

<?php

if(isset($_GET['string']))
{
  echo ("Your string was: " . $_GET['string']);
}

?>

save as myAJAX.php

Move both to your server. Open example.html. You now have a working AJAX call.

You will see that the JAVASCRIPT and the PHP are totally separate, and the JAVASCRIPT sends information to the PHP which simply waits …

ryantroop 177 Practically a Master Poster
ryantroop 177 Practically a Master Poster

depending on your back end... this seems like it's more of a database/sort issue... but if really all you need to do is append +whatever to the url...

function submit()
{
    var mySelectBox = document.getElementById("mySelectBox");
    var myWord = mySelectBox.options[mySelectBox.selectedIndex].text;

    var URL = document.URL;
    if (URL.lastIndexOf("/") != URL.length)  /* this assumes URL ends with "/" */
        URL += "+";

    URL += String(myWord); //cast for sanity


    window.location = URL;  //if this doesn't work try window.location.href = URL (or use both for sanity).
}

so on your "submit" button, your onclick="submit();" alternatively, if you are submitting a form you can do onsubmit="submit();" on the form... so many ways to cook chicken...

if your URL does not end with "/" you can do any number of string surgery operations to figure out if you need to pre-append a "+". For example, you can use URL.lastIndexOf(".com") != URL.length - 4

This is really not the best way to do this, but if it is what's required for your system then it's what you need.

ryantroop 177 Practically a Master Poster

I can't see any reason to ever do this... what's the point of a checkbox if you can't interact with it?

However, with js you could just

<html> 
<--! doctype is whatever you want... -->
<head>
<title>Perpetual Checkbox</title>
<script type="text/javascript">
function onload()
{
    var ChkBx = document.getElementById("mycheckbox");
    ChkBx.checked = true;
}
function setChecked()
{
    document.getElementById("mycheckbox").checked = true;
}
</script>
</head>
<body onload="onload();">
<input type="checkbox" name="whatever" value="1" id="mycheckbox" onclick="setChecked();"/>

</body>
</html>

This would perpetually make your checkbox checked... maybe I am misunderstanding you and what you need... but I would think that you want a "hidden" input field, where you can set a "static" value.

<input type="hidden" name="whatever" value="whatever" />

if you want it to persist through page refreshes, you will need a method to "save" the state you are in. You can either append stuff to the URL (but a hard refresh or a direct hit to the root URL will kill that idea), or you can set a cookie, save to a database or storage method of choice...

ryantroop 177 Practically a Master Poster

so to summarize what the two posters above so eloquently stated:

PHP is a server language, which means it's called before a page renders, and the browser is given control over content. So, PHP itself cannot possibly "know" that there is javascript on the page, and that it is trying to do something that warrants communication.

In turn, javascript is a browser (or, client side) langauge, and is given control after the page has been rendered (technically... in reality, it is given control as the DOM loads, or as a line of javascript is read by the browser).

To do what you want to do, you need to have a page designed to accept a GET or POST from a javascript AJAX query.
http://www.w3schools.com/ajax/

TL;DR: Make a separate PHP page that will do the processing, make an AJAX call to that page. JSON or not, it works just fine if you expect what you get.

ryantroop 177 Practically a Master Poster

firefox's event bubble is "backwards" meaning it goes from top down. In theory, firefox is the "broken" one in your scenario.

Every other browser works via bubbling upwards, and the onclick event will fire on the root element, and go up the body to the document/window.

Your argument about how not wanting to work with IE and other "broken" browsers betrays your limited experience with javascript. All browers have their quirks. IE has more, for sure, but they are getting fewer. However, firefox is just as bad at implementing their own interpretation of ECMA as everyone else, and they break stuff that "should work right."

Start looking into developing for cross browser, and issues like this will start to happen less and less. Sure, it's more work for you now and you will have a TON to catch up on. In the long run, though, maintainability, code re-use, and managing your site will become so much easier.

If you wish to insist that firefox is the end all be all of browsers, then be sure to start phrasing your questions as "I want to make my code work in firefox" and stop worrying about Chrome or Safari or any other webkit, IE, or Konquerer based browsers, as they will ultimately all be different and have something different about them.

The solution by Jorge is the best anyone has given to make your issue non-existent across all browsers. You are asking for the value of a select after it has been …

ryantroop 177 Practically a Master Poster

Not to be a jerk, but not developing for IE is like asking a majority of PC users to simply ignore your website...

As to your problem, you can use window.location. href = "http://mywebsite.com";

If you do not put in a protocol, it should append a relative path to the domain.

ryantroop 177 Practically a Master Poster

I see what you did, you made temporary variables to hold the queries.. neat.

However, I was under the impression that you could put the logic directly into the query, and not have to run it as such.

ryantroop 177 Practically a Master Poster

my SQL is.. getting better, so take this as a "starting point" and maybe someone can fix it if I did it wrong..

It looks like youre using variables as it is, so why not use SQL as a language and do your logic as necessary... (Im summarizing your code, so feel free to add the columns as necessary).

declare @FIRSTNAME varchar(255), @GENDER char(1)

SELECT * FROM PATIENT_INFO WHERE
 @FIRSTNAME = CASE
 WHEN (@FIRSTNAME is not NULL)
 THEN FIRSTNAME LIKE @FIRSTNAME order by @FIRSTNAME
 ELSE
 order by @GENDER

You will forgive me if I am totally wrong.. I learned SQL on MySQL, and I am currently forcing MSSQL/Prepared Statements into my brain.

ryantroop 177 Practically a Master Poster

this link, and the associated links within, will probably get you off in the right direction.

http://www.w3.org/2010/05/video/mediaevents.html

Ryan

ryantroop 177 Practically a Master Poster

This is, by far, my favorite site for regex testing. Make sure you use the Preg radio button, and have fun: http://www.regextester.com/

ryantroop 177 Practically a Master Poster

Ahh I misread.

There may be something in another part of you script that states any of the following:

$_SESSION['username'] = '';

if($_SESSION['username'] = ''){}; //notice the missing ==, in this case it will set the variable instead of checking to see if something is there

Im sorry. When I read the initial post, I read it that all of your session variables were being lost.

I still encourage you to exit after a redirect, and doing the redirect after all session variables are in place.

ryantroop 177 Practically a Master Poster

While it's true that if you do not specifically exit() the script it will (should) continue to run, you may want to consider moving line 3 to line 28, and see if that solves your problem. This will make your session variables get set, THEN redirect.

You may also wish to add exit(); after each header redirect. This will stop all processes other than the redirect, and not confuse the server as to what you want to do.

That should solve your problem.

If not, I will read the code more closely.

Please note: I know I am not answering your most recent question, but seeing your code led me to a different answer. Normally, you would use session_write_close() after all session variables are set, but before a header redirect. It is rather uncommon to need to use session_write_close(), and the above should solve your problem.

ryantroop 177 Practically a Master Poster

Try hard coding session_start() as the first thing on each page, and not as part of the include.

If you are redirecting, you may have to session_write_close() before the header change.

It may be something to do with the way you are accessing variables, as well.

As a last bit, it may be a setting within php.ini, and how it handles sessions/cookies. The particular setting in mind escapes me, at the moment, but I will try to look it up if the other two options fail.

ryantroop 177 Practically a Master Poster

I love eclipse with the PHP extension. If you are looking for a testing platform, you will not find many good ones (and quite frankly, you are more than likely using the language wrong).

Best platform to test - get a cheap/free web host, turn on error reporting, use eclipse or netbeans, upload and test. Wash, rinse, repeat.

ryantroop 177 Practically a Master Poster

I think what youre asking is for this:

This is assuming your text document is split by "." as you have above, so...
Joe Cren(.)Ryan Troop(.)Eddie Vedder(.)Led Zepplin(.) //or something similar

if you do:

$array = explode("(.)", fread($fp, filesize($filename)));
//this array is populated ['Joe Cren', 'Ryan Troop', 'Eddie Vedder', 'Led Zepplin']

To use those, I can do:

foreach($array as $key=>$value)
{
//do something with a name, one at a time
echo "Name ".$key.": ".$value."<br>";
}

The above will output:
Name 0: Joe Cren
Name 1: Ryan Troop
Name 2: Eddie Vedder
Name 3: Led Zepplin

Alternatively, you can access the items directly using:
echo $array[0]; //will output: Joe Cren

and we can make a for loop as you have done:

for($i=0; $i<count($array);$i++)
{

echo "Name ".($i+1).": ".$array[$i]."<br>";

}

The above will output:
Name 1: Joe Cren
Name 2: Ryan Troop
Name 3: Eddie Vedder
Name 4: Led Zepplin

Hope that clarifies for you.

Ryan

EDIT: I posted at the same time as the above. The above method is much more elegant and easier to read.

ryantroop 177 Practically a Master Poster

^clever catch

ryantroop 177 Practically a Master Poster

I didnt add any redirects. You need to change the comments out.

//login stuff needs to be actual php commands..

redirect?
header("Location: mypagetogo.php");
exit();

error message?
echo "You failed to log in!!";

I left that part up to you.

You will also need to change the names in the SQL query, as well, to match your table.

ryantroop 177 Practically a Master Poster

so by your calling me a "dumb monkey" you went from having someone willing to help, to another person who will just ignore you.

You are what makes the internet rot. I for one will be happy to see you fail.

happygeek commented: well said +11
ryantroop 177 Practically a Master Poster

Also, if you are going to use a salt, it needs to be unique for each password - it defeats the purpose of a salt if they are all the same, as a rainbow table can be made by injecting the salt.

You can even be so bold as to store the salt in the database along with the username, because it would take a rediculously long time to crack a single password with the salt, and then have to do it all over for the next one.

If you want to go even further, you can use salt and pepper, and pepper can be a global variable that is stored in a protected area that no one will never see unless they gain access to your FTP/root, in which case you have bigger problems than your database being cracked.

ryantroop 177 Practically a Master Poster

blue, since you are messing around with all your different encryptions types you may have mixed yourself up.

Whatever you encrypt the password with during creation, you must use to check against the password in login.

So, if your "signup" page uses MD5, then your login script must also use MD5.

You may also have encryption turned on in your database, in which case you would be encrypting and encrypted string - but PHP would have no idea that it has been re-encrypted. So make sure that your table column is not, for any reason, encrypted during an insert. If it is, you need to decrypt it during a select (assuming you have the right key).

If you created your own tables, you would know if encryption is turned on for the insert/update.

In general, the creation process would be something like this at creation (I am not sanitizing anything for the sake of simplicty):

<?php

if($_POST) {
$usr = $_POST['usrnm'];
$pass = hash('md5', $_POST['pswrd']);

$query = "INSERT INTO login (username, password) VALUES ('$usr', '$pass');";

$result = mysql_query($query);

if(mysql_affected_rows($result) == 1){
echo "Insert Complete!";
session_start();
$_SESSION['username'] = $usr;
//redirect or whatever...
}else {
echo "Insert failed!";
//redirect or whatever...
}
}

?>

Then our retrieval at login:

<?php

if($_POST){
$usr = $_POST['usrnm'];
$pass = hash('md5', $_POST['pswrd']);

$query = "SELECT username u, password p FROM login WHERE username='$usr' AND password='$pass';";

$result = mysql_query($query);

if(mysql_num_rows($result)==1) {
//login stuff
}else{
//login failure
}
}

?>

Hope that helps,

Ryan

ryantroop 177 Practically a Master Poster

Im not sure why you want to redirect away from your site 80% of the time, as that would pretty much ensure 80% of the people would not want to visit your site because it's useless.

However, if you wish to pursue this you have 2 options.

1 - pure PHP (with a database of links), and, just as you said, do random(100) and if it's > 80, then echo "href='mylink'" as drawn from database A, and if < 80, then href='fakelink' as drawn from database B.

2 - Use javascript and at runtime, change it in the same fashion as above.

While I am trying to keep a personal tone out of this, I need to say that pushing 80% of your traffic away is stupid and counter productive... but I'm sure you have your reasons (of which, I have no desire to learn).

EDIT: I did not go to the site you linked. Im assuming if you want people to "believe" they are going to one link, but are redirected to another, you need to use javascript and onclick()

ryantroop 177 Practically a Master Poster

sorry, let me be more clear...

$sql= "SELECT * FROM employee WHERE uname='$user' and pswrd='$encryptpass'";

$rs = mysql_query($sql) or die(mysql_error());
if(mysql_num_rows($rs) === 1) //if === does not work, try ==
 {
  $row = mysql_fetch_array ($rs);
  echo "name: " . $row['fname'] . " " . $row['lname'];
 }
else
 {
 ....