I did post something earlier put this time I am going to post all of it.I am getting error message and it will not show up when i try to pull it up on local host.
Here's the code:
This one is includeindex.php
if ($_POST['submit'] != "") {
if ($_POST['name'] != "") {
session_start();
$_SESSION['name'] = $_POST['name'];
TopNavigation("PHP Includes Example - ECA236", "PHP Includes", $_SESSION['name']);
} else {
header("Location:includindex.php");
exit;
}
} else {
TopNavigation("PHP Includes Example - ECA236", "PHP Includes");
echo "<div class=\"formtable\">\n";
echo "<br>";
echo "<form action=\"" . $PHP_SELF . "\" method=\"post\">\n";
echo "Please enter your name:<input type=\"text\" name=\"name\">\n";
echo "<input type=\"submit\" class=\"btnSubmit\" value=\"Enter\" name=\"submit\">\n";
echo "</form>\n";
echo "<br>";
echo "</div>\n";
Footer();
}
?>
This one is header
<?php
function TopNavigation($pagetitle, $pageheading, $username = '') {
echo "<html>\n";
echo " <head>\n";
echo " <title>" . $pagetitle . "</title>\n";
echo " <link href=\"../style.css\" type=\"text/css\" rel=\"stylesheet\">";
echo " </head>\n";
echo " <body>";
echo " <h1>" . $pageheading . "</h1>\n";
echo " <hr>\n";
echo " <p class=\"tiny\">" . date("F j,Y") . "</p>";
if ($username != '') {
echo "<div align=\"center\">\n";
echo "Use a different name | About | Signout\n";
echo "</div>\n";
echo "<p>Welcome. " . $username . "!";
}
}
function Footer() {
echo "</body>\n";
echo "</html>\n";
}
?>
This one is about.php
<?php
session_start();
include("include/header.php");
if (!isset($_SESSION['name'])) {;
header("Location:includeindex.php");
exit;
} else {
TopNavigation("About Me -ECA236", "About Me", $_SESSION['name']);
echo "<p>Here is a little about me. I am a mother of twin girls who are 9 </p>\"n;
echo " < p>I been married for 5 years but been with my husband for 11 years </p > \"n;
echo "<p > I am attending college for Computer Programming and Database Mangament </p > \"n;
echo "<p > After I get done with this degree I am want to go back for Web Design </p > \"n;
echo "<p > since half my classes are web design now . I enjoy camping,bon fires and </p > \"n;
echo "<p > playing video games, hanging out with friends and family .</p > \"n;
Footer();
}
?>
This one is signout.php
<?php
session_start();
if (isset($_SESSION['name'])) {
session_destroy();
session_start();
}
header("Location:includeindex.php");
exit;
?>
I can not get it to show up and work at all. I have no clue why it is not doing it. Can someone please help me.
I keep getting errors no matter what I fixed and it doesnt show up when you look at it online..
here the errors i get:
Notice: Undefined variable: PHP_SELF in C:\wamp\www\includeindex.php on line 19
Undefined index: submit in C:\wamp\www\includeindex.php on line 4
Warning: include(include/header.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\about.php on line 3
Warning: include() [function.include]: Failed opening 'include/header.php' for inclusion (include_path='.;C:\php\pear') in C:\wamp\www\about.php on line 3
Fatal error: Call to undefined function TopNavigation() in C:\wamp\www\about.php on line 9
All of your echo statements in the TopNavigation() function are still incorrectly quoted. Instead of \"n;, they should end with \n";
// Wrong
echo "<p>Here is a little about me. I am a mother of twin girls who are 9 </p>\"n;
// Should be:
echo "<p>Here is a little about me. I am a mother of twin girls who are 9 </p>\n";
---^^^^
in your php.ini change display_errors=Off to display_errors=On
Related
I'm using Slim framework for my project. I've copied the Slim folder to my project directory.
No following is the code I'm having issue with :
PHP Code(requestdemo.php):
<?php
require 'Slim/Slim.php';
/* Invoke the static "registerAutoloader()" function defined within Slim class.
* Register the autoloader is very important.
* Without doing it nothing will work.
*/
\Slim\Slim::registerAutoloader();
//Instantiate Slim class in order to get a reference for the object.
$application = new \Slim\Slim();
$application->get(
'/request',
function()
{
GlOBAL $application;
echo " <br/><b>request methods</b>";
echo "<br/>application->request->getMethod()=".$application->request->getMethod();
echo "<br/>application->request->isGet()=".$application->request->isGet();
echo "<br/>application->request->isPost()=".$application->request->isPost();
echo "<br/>application->request->isPut()=".$application->request->isPut();
echo "<br/>application->request->isDelete()=".$application->request->isDelete();
echo "<br/>application->request->isHead()=".$application->request->isHead();
echo "<br/>application->request->isOptions()=".$application->request->isOptions();
echo "<br/>application->request->isPatch()=".$application->request->isPatch();
echo "<br/>application->request->isAjax()=".$application->request->isAjax();
echo "<br/> <br/><b>request headers</b>";
$headers = $application->request->headers;
foreach($headers as $k=>$v)
{
echo "<br/>$k => $v";
}
echo "<br/> <br/><b>request body</b>";
echo "<br/>body=".$application->request->getBody();
echo "<br/> <br/><b>request variables</b>";
echo "<br/>width=".$application->request->params('width');
echo "<br/>height=".$application->request->params('height');
echo "<br/> <br/><b>request get variables</b>";
echo "<br/>width=".$application->request->get('width');
echo "<br/>height=".$application->request->get('height');
echo "<br/> <br/><b>request post variables</b>";
echo "<br/>width=".$application->request->post('width');
echo "<br/>height=".$application->request->post('height');
echo "<br/> <br/><b>resource uri</b>";
/*From the below line I'm not able to see the output in a browser.*/
echo "<br/>rootUri=".$application->request->getUri();
echo "<br/>resourceUri=".$application->request->getResourceUri();
echo "<br/> <br/><b>request ajax check</b>";
echo "<br/>rootUri=".$application->request->isAjax();
echo "<br/>resourceUri=".$application->request->getResourceUri();
echo "<br/> <br/><b>request helpers</b>";
echo "<br/>content type=".$application->request->getContentType();
echo "<br/>media type=".$application->request->getMediaType();
echo "<br/>host=".$application->request->getHost();
echo "<br/>scheme=".$application->request->getScheme();
echo "<br/>path=".$application->request->getPath();
echo "<br/>url=".$application->request->getUrl();
echo "<br/>user agent=".$application->request->getUserAgent();
});
$application->run();
?>
The file 'requestdemo.php' is present in the directory titled "slimsamples" at location /var/www/slimsamples
As I hit the URL 'http://localhost/slimsamples/requestdemo.php/request' I'm able to see only the part of output in a browser window. From where I'm not able to see the output I've commented in my code. I'm not able to see the output after line resource uri. See the screenshot for further understanding.
Also there is no syntactical error in it then why it's happening I'm not understanding.
Can someone please find out the mistake I'm making here?
Thanks in advance.
Use: request->getUrl()
(You used request->getUri())
See http://dev.slimframework.com/phpdocs/classes/Slim.Http.Request.html#getUrl
I have a form for uploading files to a web server and then saving the filepath along with the email address it's connected to and a serial code to a sql table. The problem is, what if someone uploads a file with the same name as a previous person or upload? To fix this, I want to name the file "insert serial code here".mp4 or .pdf. When I do this it comes up with the following error:
Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in /home/content/98/10339998/html/scripts/upload.php on line 57
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php7UzcdG' to '../story_files/' in /home/content/98/10339998/html/scripts/upload.php on line 57
Stored in: ../story_files/
Here is a full echo example:
Customer's unique serial code: d0d74-ef227
Upload:
Type: application/pdf
Size: 14.4287109375 kB
Temp file: /tmp/php7UzcdG
Warning: move_uploaded_file() [function.move-uploaded-file]: The second argument to copy() function cannot be a directory in /home/content/98/10339998/html/scripts/upload.php on line 57
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php7UzcdG' to '../story_files/' in /home/content/98/10339998/html/scripts/upload.php on line 57
Stored in: ../story_files/
../story_files/
Upload: file.mp4
Type: video/mp4
Size: 374.6396484375 kB
Temp file: /tmp/phpQczVLm
file.mp4 already exists.
Serial Code Emailed to Customer Michael
Here is the code, note the difference between the video and story part of it, I didn't convert the video part yet it is the fully-working original code. Also, PHP thinks that the serial code is a filepath, why is that? The code is simply a 10 digit series of letters and numbers two sets of 5 digits with a dash between to simplify reading it.
<title>Uploading Files and Sending Serial Code To Customer</title>
<!--Favicon Code-->
<link rel="shortcut icon" type="image/x-icon" href="../images/favicon.ico" />
<!--Favicon Code-->
<link href="/CSS/CSS.css" rel="stylesheet" type="text/css" />
<div align="center">
<p><span class="linkText">Home Contact Us Products</span> </p>
<p> </p>
<h2 class="headingText"><img src="/images/banner.jpg" alt="legendmaker - makes legends: banner" width="297" height="473"></h2>
<h2 class="headingText"> </h2>
<h2 class="headingText">Upload Story Files</h2>
</div>
<?php
// before we do anything make sure there is a correct password (we don't want unauthorized usage)
$password = trim($_POST['password']);
if ("*****" == $password)// not going to post my pass on the forums :P
{
///// generate unique serial code ///////////////////////////////////////////////////////////////
$string1 = substr(md5(uniqid(rand(), true)), -5, 5);
$string2 = substr(md5(uniqid(rand(), true)), -5, 5);
$serial = sprintf('%s-%s', $string1, $string2);
echo "Customer's unique serial code: ";
echo $serial;
echo " ";
/////end of generate unique serial code ///////////////////////////////////////////////////////////////
///story file upload///////////////////////////////////////////////////////////////////////////////////
if ($_FILES["file"]["size"])
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "<br>" . "<br>" . "<br>" . "Upload: " . $_FILES["file"]["$code"] . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("stories/" . $_FILES["file"]["$code"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"../story_files/" . $_FILES["file"]["code"]);
echo "Stored in: " . "../story_files/" . $_FILES["file"]["$code"] . "<br>";
$storyPath = sprintf("../story_files/" . $_FILES["file"]["$code"]);
echo $storyPath;
}
}
}
else
{
echo "No story file was chosen, this is not an error just a notification. Any other files selected will still upload correctly. ";
}
///video file upload////////////////////////////////////////////////////////////////////////////////
if ($_FILES["videoFile"]["size"])
{
if ($_FILES["videoFile"]["error"] > 0)
{
echo "Return Code: " . $_FILES["videoFile"]["error"] . "<br>";
}
else
{
echo "<br>" . "<br>" ."Upload: " . $_FILES["videoFile"]["name"] . "<br>";
echo "Type: " . $_FILES["videoFile"]["type"] . "<br>";
echo "Size: " . ($_FILES["videoFile"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["videoFile"]["tmp_name"] . "<br>";
if (file_exists("../video_files/" . $_FILES["videoFile"]["name"]))
{
echo $_FILES["videoFile"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["videoFile"]["tmp_name"],
"../video_files/" . $_FILES["videoFile"]["name"]);
echo "Stored in: " . "../video_files/" . $_FILES["videoFile"]["name"] . "<br>";
$videoPath = sprintf("../video_files/" . $_FILES["file"]["name"]);
echo $videoPath;
}
}
}
else
{
echo "No video file was chosen, this is not an error just a notification. Any other files selected will still upload correctly. ";
}
/// submit information to database/////////////////////////////////////////////////////////////////////
$username="storycodes";
$password="Legendmaker1!";
$con = mysqli_connect("storycodes.db.10339998.hostedresource.com",$username,$password);
if (!$con)
{
die('Could not connect: ' . mysqli_error());
}
$email = $_POST['email'] ;
$submitInformation = "INSERT INTO `storycodes`.`storycodes` (`code`, `email`, `video`, `story`) VALUES ('$serial', '$email', '$videoPath', '$storyPath');";
mysqli_query($con, $submitInformation); // submits information to database for later recollection
////////////////////end of submit to database///////////////////////////////////////////////////////////
/////////////////// email the code to customer//////////////////////////////////////////////////////////
require_once '../PHPMailer_5.2.2/class.phpmailer.php';
$name = $_POST['name'] ;
$body = "Thank you for using legendmaker $name! Your story has been completed and will now be accesible at www.thelegendmaker.net/stories.html On that page you will be required to enter a serial code in order to access your files. We require a serial code in order to access files because we care about our customers and security is a concern. Your serial code is: $serial";
$mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch
try
{
$mail->AddAddress($email, $name);
$mail->SetFrom('fakeemail1#gmail.com', 'Sender Name');
$mail->AddReplyTo('fakeperson#yahoo.com', 'Fake Name');
$mail->Subject = "Message From Legendmaker: $name your story is now complete.";
$mail->Body = $body;
$mail->Send();
echo "<br>" . "<br>" . "Serial Code Emailed to Customer $name</p>\n";
echo "<img src='/images/knight-success.png' alt='success' width='429' height='791' />";
} catch (phpmailerException $e) {
echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
echo $e->getMessage(); //Boring error messages from anything else!
}
/////////////////// end of email code///////////////////////////////////////////////////////////////////
}
else
{
echo "incorrect password";
}
/// end of file uploads//////////////////////////////////////////////////////////////////////////
?>
<link href="/CSS/CSS.css" rel="stylesheet" type="text/css" />
<p>
<!--google cart code ------------------------------------>
<script id='googlecart-script' type='text/javascript' src='https://checkout.google.com/seller/gsc/v2_2/cart.js?mid=215313740482542' integration='jscart-wizard' post-cart-to-sandbox='false' currency='USD' productWeightUnits='LB'></script>
</p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p align="center">Contact Us Site Owner Upload Service Agreement</p>
You use $_FILES["file"]["code"] instead of $_FILES["file"]["name"] for the file name which doesn't exist so the result is that you're passing a directory as the second argument.
move_uploaded_file($_FILES["file"]["tmp_name"],
"../story_files/" . basename($_FILES["file"]["name"]));
EDIT
if you want to use the serial code that is generated to be the file name just concatenate it to the directory string in move_uploaded_file
move_uploaded_file($_FILES["file"]["tmp_name"],
"../story_files/" . $serial);
Please Help, nothing i add after the ?> works, i tried to put the code in a echo, but its not working would someone please put together a JSFiddle for me or point me in the right direction, i am fairly new with PHP, Thanks for the help
<?php
$filepath = 'http://www.godsgypsychristianchurch.net/music.json';
$content = file_get_contents($filepath);
$json = json_decode($content, true);
foreach ($json['rows'] as $row)
{
if ($_GET['album'] == $row[doc]['album'])
{
echo "<title>{$row[doc]['album']}</title>";
echo "<table align=\"center\" border=\"0\"><tr><td valign=\"top\" width=\"330\">";
echo "<img src=\"{$row['doc']['artwork']}\" alt=\"my image \" width=\"250\" /><br /><br />";
echo "<div class=\"albuminfo\" id=\"albuminfo\">";
print ' Download entire album.<p>';
echo "<font color=\"#fff\">Album: {$row[doc]['album']}</font><br />";
echo "<font color=\"#fff\">Church: {$row[doc]['church']}</font><br />";
echo "<font color=\"#fff\">Description: {$row[doc]['des']}</font><P><br /><P>";
echo "Tweet<br><br>";
print '<div id="like-button"></div>';
echo "<td valign=\"top\">";
echo "<div class=\"playlist\" id=\"playlist\">";
echo "<ol>";
$songCount = 0;
foreach ($row['doc']['tracks'] as $song) {
++$songCount;
$songUrl = $row['doc']['baseurl'] . urldecode($song['url']);
echo "<li>{$song['name']}<div id=\"download\">Download</li>";
}
echo "</ol>";
echo "<br><div id=\"player\"><audio preload></audio></div>";
echo "</div>";
echo "<P>";
echo "<small>To download a single MP3 at a time:</br><b>Windows OS:</b> hold the ALT button on the keyboard and click the Download button<br><b>Mac OSX:</b> hold the OPTION button on the keyboard and click the Download button<P><BR><b>Controls:</b><br>Play/Pause = spacebar</br>Next track = Right arrow<br>Previous track = Left arrow";
echo '</tr></td></table>';
}
}
exit;
?>
<!----NOTTING SHOWING UP---->
<!-- begin htmlcommentbox.com -->
<div id="HCB_comment_box">HTML Comment Box is loading comments...</div>
<script type="text/javascript" language="javascript" id="hcb"> /*<!--*/ if(!window.hcb_user){hcb_user={};} (function(){s=document.createElement("script");s.setAttribute("type","text/javascript");s.setAttribute("src", "http://www.htmlcommentbox.com/jread?page="+escape((window.hcb_user && hcb_user.PAGE)||(""+window.location)).replace("+","%2B")+"&opts=0&num=10");if (typeof s!="undefined") document.getElementsByTagName("head")[0].appendChild(s);})(); /*-->*/ </script>
<!-- end htmlcommentbox.com -->
Because you are using exit, which terminates the script. Get rid of that and it will continue to output the HTML underneath.
http://php.net/manual/en/function.exit.php
Omit the exit.
Exit will end Php processing.
With php exit the parser stops, and hands back all the content gathered until that point to the web server. Simply delete the exit; row.
I have scoured the net and watched endless You Tube vids but cant find an answer to this. Most of what I am finding is for more complex issues and I am just a newbie starting out.
I am trying to learn OOP. I took an old PHP example I had lying around and decided to try converting it to oop. All it is is a loop with a counter. Problem is I cant get it to work out at all.
My original view page was this...
<html>
<head><title>1 Loop</title></head>
<body>
<h2>1 Loop for age</h2>
<?php
$age=18;
while ($age <= 20)
{
echo ("You are " . $age . " years old. <br /> You are not old enough to enter. <br /><br />");
$age++;
}
echo ("You are " . $age . " You may enter!");
?>
</body>
</html>
Now I am trying to create a class_lib page and a php page. Here is my class page:
<?php
class person {
public $age;
function __construct($persons_age) {
$this->age = $persons_age;
}
function get_age() {
while ($age <= 20)
{
echo ("You are " . $age . " years old. <br /> You are not old enough to enter. <br /><br />");
$age++;
}
echo ("You are " . $age . " You may enter!");
return $this->age;
echo $this->age;
}
}
?>
And lastly, my php view:
<html>
<head>
<title>1 Loop</title>
<?php include("class_lib.php"); ?>
</head>
<body>
<h2>1 Loop for age</h2>
<?php
$obj = new person(17);
echo $obj->get_age();
?>
</body>
</html>
Can someone give me a few pointers as to where I am going wrong?
In your get_age() function you use $age instead of using $this->age. The latter uses the class variable, instead of a local variable (that does not exist).
Remove the echo $this->age; line which resides after the return-statement of the function. It is never reached and does not seem to have any value, as you already printed the age.
Your get_age() function is wrong, you're trying to access the $age variable like a local variable though it should be accessed like a class variable.
Try this:
function get_age() {
while ($this->age <= 20)
{
echo ("You are " . $this->age . " years old. <br /> You are not old enough to enter. <br /><br />");
$this->age++;
}
echo ("You are " . $this->age . " You may enter!");
return $this->age;
}
Remove the echo function, the last line of it, because this will never get called since you any code after the return call is dismissed.
Also, you're already echoing the content you're returning in your php view.
I want to know how to get the original URL from php
For example:
example.php
<?php
header('location:test.php');
?>
I want to get test.php from example.php.
example.php
<?php
header('location:' . $_SERVER['HTTP_REFERER']);
?>
This should work fine.
Redirection with some delay say after 5 sec wait.
function js_redirect($url, $seconds)
{
echo "<script language=\"JavaScript\">\n";
echo "<!-- hide code from displaying on browsers with JS turned off\n\n";
echo "function redirect() {\n";
echo "window.parent.location = \"" . $url . "\";\n";
echo "}\n\n";
echo "timer = setTimeout('redirect()', '" . ($seconds*1000) . "');\n\n";
echo "-->\n";
echo "</script>\n";
return true;
}
js_redirect("http://www.exapmle.com",5); // Redirect after 5 sec
you forget to use
ob_start();
in first of your code :D
elsewhere you can use js in this case , for example :
echo 'javascript:window.location="http://example.com";';