/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] fopen won’t work

I’m trying to open a html page using fopen but it doesn’t seem to work. Here is my code:

[code]
<?php

if ( isset ($_POST[“submit”])) {

@mysql_connect (“localhost”, “root”, “loonytunes”)
or die (“Could not connect to server”);

@mysql_select_db (“test”)
or die (“Could not connect to database”);

$query = “select * from `login database` where username='{$_POST[“username”]}’ and password='{$_POST

[“password”]}'”;

$result = mysql_query ($query);

if ($result) {
$handle = fopen(“http://localhost/testFolder/landingPage.html”, “r”);
} else {
echo “You are not a member yet. Please register”;
}

}

?>
[/code]

I’ve done some research on this matter and what I’ve found out is that I might not have permission to access these files or that I have to change some configuration in PHP or apache to allow it to work but I’m not sure how to do that.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 22.2006 — What exactly are you trying to do? fopen() as you've used it here will only open a file handle (if successful). By itself nothing else will be done with that file. If you want to redirect the user to that page, just use the header() function:
[code=php]
header("Location: http://localhost/testFolder/landingPage.html");
[/code]
Copy linkTweet thisAlerts:
@The_Little_GuyOct 22.2006 — Print the content:
[code=php]$handle = fopen(http://localhost/testFolder/landingPage.html", "r");
while (!feof($handle)){
$text = fgets($handle);
echo $text;
}[/code]

Redirect:
[code=php]$handle = fopen(http://localhost/testFolder/landingPage.html", "r");
header("Location: $handle");[/code]
Copy linkTweet thisAlerts:
@mark_yiehauthorOct 22.2006 — cool thanks everyone. I would have never thought the function to open a new web page would be called header().

Now that I know, I've run into another problem. I'm running apache on my computer and I test everything locally, so when I try to redirect the page to another page on my local machine using the header() function it doesn't work, but it works fine when I redirect it to a www site. Here's what I've got:

<i>
</i>
header ("Location: http://localhost/testFolder/landingPage.html");



that doesn't work, but this works

<i>
</i>header ("Location: http://www.someDomain/somePage.html");


What do I need to know? Thanks.
Copy linkTweet thisAlerts:
@mark_yiehauthorOct 22.2006 — neve mind about the last post. For some reason, the file that I pointed to was corrupt, so the browser was not able to locate it even though when I looked in that directory, it was sitting right there. I deleted the corrupted file and created a new one and it works fine.
×

Success!

Help @mark_yieh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...